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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.