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
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 |
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 |
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 |
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 |
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 |
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 |
SAS System ?
Can you continue to write code while the rest of the people on the floor where you work have a noisy party to which you were not invited?
What would the following datastep do? Data _null_; Set Dist end=eof; Call Symput("xx"!!left(put(_n_,2.)),&dimension); If EOF then Call Symput('numrows',left(put(_n_,2.))); Run; dimension is a macro variable that is being passed here
what is the use of sas management console? : Sas-di
i have multiple .csv files in a unix directory. every file is having variable names as header.even for empty file also. suppose take 3 files a.csv b.csv c.csv a.csv contains data as name;age,salary; raja;34;4000; ravi;33;5000; kumar;25;3000; b.csv contains data as name;age,salary; ajay;40;4500; and c.csv contains name;age,salary; (only headers) Now i want to import and append all these files in to a single dataset. i tried infile statement with *.csv to import all at a time. but i m not getting correct data. please help me . its urgent. thank you in advance
how do i get last 10obs from a dataset when we don't know about the number of obsevations in that dataset?
what is broad cast agent? : Sas-bi
what is option year cuttoff in sas
What are TEAEs
2 Answers Accenture, Quintiles,
How we will Developing new reports Using Data step programming and Macros ?
How would you code the criteria to restrict the output to be produced?
What is interleaving in SAS?