Hello!
I am trying to assign a value to duplicate rows.
This is the data I have:
Medrec Results
771441 Growth
771441 Growth
771441 No Growth
771441 No Growth
771441 No Growth
This is the data I want:
Medrec Results Growth
771441 Growth Y
771441 Growth Y
771441 No Growth Y
771441 No Growth Y
771441 No Growth Y
This is what I've tried but I only get one row to have Growth = 'Y'
You forgot the RETAIN statement so that the value of GROWTH does not get set to missing at the start of each iteration of the data step.
Also what value to you want it to have if RESULTS is neither Growth nor No Growth? If you don't have another ELSE clause then any MEDREC group where the first value is neither of those two very specific values will retain the value calculated for the previous group.
You forgot the RETAIN statement so that the value of GROWTH does not get set to missing at the start of each iteration of the data step.
Also what value to you want it to have if RESULTS is neither Growth nor No Growth? If you don't have another ELSE clause then any MEDREC group where the first value is neither of those two very specific values will retain the value calculated for the previous group.
It just tells SAS not to reset the new variable to missing at the start of the next iteration. So since it has no executable component you can place the retain statement any where in the data step.
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0t2ac0tfzcgbjn112mu96hkgg9o.htm
If you only have two possible values then why not just create a binary variable. That is easier to create
data medrec3;
set medrec2;
by medrec;
if first.Medrec then growth= (results = 'Growth');
retain growth;
run;
and easier to work with.
I just did some searching and added it like this
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 16. Read more here about why you should contribute and what is in it for you!
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: