calculate the sum of value using only DATA STEP.
data count_;
input year name $ value;
cards;
2006 xxx 10
2007 yyy 12
2006 xxx 20
2008 yyy 15
2007 xxx 15
;

out put should be like this
year name T_value
-----------------------
2006 xxx 30
2007 xxx 15
2007 yyy 12
2008 xxx 15

Answers were Sorted based on User's Feedback



calculate the sum of value using only DATA STEP. data count_; input year name $ value; cards; 20..

Answer / rpd

I can give logic part, rest kindly manage :)

step 1:proc sort the dataset by "PID YEAR"
step2 :in the datastep "SET" it using by PID YEAR
create a temp variable say _SUM and RETAIN _SUM,
reset _SUM=0 on FIRST.YEAR.
T_VALUE=_SUM+VALUE

I guess this will work

Is This Answer Correct ?    2 Yes 0 No

calculate the sum of value using only DATA STEP. data count_; input year name $ value; cards; 20..

Answer / ravi s

it need two steps

step 1 : proc sort; by year name;run;

Step 2: data total (drop = value);
set count_;
by year name;
if first.name then T_value =0 ;
T_value + value;
if last.name then output ;
run;

Note: Hence i am doing work in data step. i need to sort
the data first by using "Proc Sort".

Kindly let me know is the any other method to do?

Is This Answer Correct ?    2 Yes 0 No

calculate the sum of value using only DATA STEP. data count_; input year name $ value; cards; 20..

Answer / xxx

here i can write the code using PROC SQL;
plz ans in DATA STEP;

proc sql;
select year,name, sum(value)as T_value from count_ group by
year, name having sum(value) order by name;
quit;

Is This Answer Correct ?    1 Yes 0 No

calculate the sum of value using only DATA STEP. data count_; input year name $ value; cards; 20..

Answer / nani

proc sort data=a;
by year ;
run;

data total ;
set a;
retain T_value;
by year ;
if first.year then T_value =0 ;
T_value + value;
if last.year then output ;
run;

proc print ;
run;

Is This Answer Correct ?    1 Yes 0 No

calculate the sum of value using only DATA STEP. data count_; input year name $ value; cards; 20..

Answer / aaa

PROC SORT DATA=COUNT_;
BY YEAR NAME;
RUN;

DATA TEST (DROP=VALUE);
SET COUNT_;
BY YEAR NAME;
RETAIN COUNT;
IF FIRST.NAME THEN COUNT = 0;
COUNT = COUNT + VALUE;
IF LAST.NAME THEN OUTPUT;
RUN;

Is This Answer Correct ?    0 Yes 0 No

calculate the sum of value using only DATA STEP. data count_; input year name $ value; cards; 20..

Answer / ashish

data new;

set tech ;
by year name;
if first.year or first.name then do;
sum=0;
end;
sum+value;
if last.year or last.name ;

run;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SAS Interview Questions

What are the ways in which macro variables can be created in sas programming?

0 Answers  


how do i get last 10obs from a dataset when we don't know about the number of obsevations in that dataset?

7 Answers   TCS,


How to import the Zip files into SAS? If it is possible in SAS? If it is posible write the code...

7 Answers  


What is the basic syntax style in SAS?

0 Answers  


what is information maps?

0 Answers   CitiGroup,


Hi all, If Anybody has Advance SAS Certification dumps??? Please share with me. Email: pramod.kalugade03@gmail.com

0 Answers  


What does PROC print, and PROC contents do?

0 Answers  


What are the best sas programming practices for handling very large datasets? : sas-grid-administration

0 Answers  


what are the new features included in the new version of sas i.e., Sas 9.1.3? : Sas programming

0 Answers  


Where do the database management systems store data and how do u import them.

2 Answers   L&T,


Describe the function and utility of the most difficult SAS macro that you have written?

0 Answers   Oracle,


how to create the AE dataset by using SDTMIG specifications and SAP plan by using UNIX platform?

0 Answers  


Categories