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

How substr function works in sas?

0 Answers  


what are the validation tools in sas?

3 Answers   TCS,


Approximately what date is represented by the SAS date value of 730?

0 Answers  


Explain the use of proc gplot? : sas-grid-administration

0 Answers  


Give some examples where proc report’s defaults are different than proc print’s defaults?

0 Answers  






what is incremental update ? is this possible in SAS OLAP CUBE STUDIO.

1 Answers   TCS,


How to get any kind of data in SAS? Is it possible to take data from notepad in SAS?

7 Answers   GSK, TNS,


how do u validate sas program

3 Answers   Accenture,


i have a dataset with 25 obs; 10th obs has like ramu,anji,ramu,azad,ramu like this. i want to know how many times the word repeats in that obs?

3 Answers  


What are all the problems you faced while validating tables and reports?

0 Answers   Accenture, Quintiles,


Give e an example of..

0 Answers  


1.How to draw pivot tables in Excel by using SAS and in which version we can use VB script for to draw pivot tables in Excel? Answer with example data. 2.What are the advantages of _NULL_ in Data steps? Can we use _NULL_ in Proc steps also? 3. How to call the macro variable into Data Steps? 4. Can we draw pivot tables in Excel using Proc SQL? Please post answers for the above questions with suitable examples, and how to use VB script for Excel using SAS.

1 Answers  


Categories