Hi All,
I am trying to create below output for variable ADY with attached program but I got something different values. Can anyone please help on this.
Required output:
subjid avisit ady_orig ady
001 1-week 6 0
001 1-month 27 21
001 3-month 90 63 (63 = 90-21+6)
001 6-month 180 90 (90 = 180- 63-21+6)
Program Used:
data od;
set od(rename=(ady = ady_orig));
by studyid usubjid avisitn avisit adtm ady_orig epoch alat;
retain ADY;
if first.usubjid then ADY = ADY_ORIG;
else ADY = ADY_ORIG - ADY;
run;
Thanks,
Kumar.
HI @Kumar6 Assuming you have ady_orig in your dataset and you want to create new variable ady, you likely want to use DIF function.
data want;
set have;
by id;
ady=dif(ady_orig);
if first.id then ady=.;
run;
HI @Kumar6 Assuming you have ady_orig in your dataset and you want to create new variable ady, you likely want to use DIF function.
data want;
set have;
by id;
ady=dif(ady_orig);
if first.id then ady=.;
run;
You cannot rename a variable to the name of a variable that already exists.
Which variable is the input and which is the output?
Can you explain the logic of your formula?
Be extremely cautious, as in don't do this with critical data sets until you've worked out any logic issues with a subset or other data set:
Data do;
set do;
This completely replaces the original Do data set if there are no syntax errors that stop the set from running.
Renaming or dropping variables means that if you need to rerun the code for some reason, such as correcting a typo from + to - , can cause errors because the original data is gone and the "old" names are no longer available at that point.
If you make an assignment value error but not a syntax error you no longer have the values you expect.
It is much better until you get more experience with SAS to use a different output data set name.
I would also ask you for more information too.
Also please provide more data using at least two SUBJIDs. Problems in this type of evolution are typical when 1) using lag functions and 2) data boundaries between two SUBJIDs records are crossed.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.