Hi, I am a beginner in SAS
I have a dataset like below
year agep N
2000 3 4
2000 5 6
2000 6 7
There are 6 age groups in my dataset. I would like to know if I can via SAS code finish the below table automatically.
year agep N
2000 1 0
2000 2 0
2000 3 4
2000 4 0
2000 5 6
2000 6 7
Thanks in advance!
Is this your actual data or sample data that resembles your actual data?
Is the agep variable always values from 1 to 6 or can it vary?
How would the programmer (in this case you or me) know that the values of N start at zero and continue up to 6 (and not go above 6)?
Do you want code that works on this exact data set, or is the problem more general and has to work on similar data sets with different values of N?
Are you trying to create a table or report? Or are you trying to create a data set?
Below one way to get there.
data have;
input year agep N;
datalines;
2000 3 4
2000 5 6
2000 6 7
;
data classdata;
year=2000;
n=0;
do agep=1 to 6;
output;
end;
run;
data want;
merge classdata have;
by year agep;
run;
proc print data=want;
var year agep n;
run;
With a merge "last wins": If there is a matching row from table have (listed last in the merge statement) then the value for agep will be taken from that table (=overwriting the value from classdata). If there is no matching row then agep will have the value from classdata.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: