Hi
i am creating a new variable visit2 , and trying to carry forward integer(e.g;8) if vstname = unscheduled visit
my code is
data vsn_srt;
set vsn_srt;
if vstname = "UNSCHEDULED VISIT" and visit1=999 then
visit2= "locf";
else visit2= visit1;
run;
will apprecaite any inputs
Thansk
You're almost there:
data vsn_srt;
set vsn_srt;
if vstname ^= "UNSCHEDULED VISIT" then visit2=visit1;
retain visit2;
run;
Please post example data in usable form (data step with datalines, posted with the "little running man"), and what you expect to get out of it.
There is no integer assignment anywhere in your code.
my dataset:
data vsn_srt;
input visit1 vstname $ 20. vst1dtc & 9.
datalines;
1 Baseline 06JUL2010
2 cycle1day1 12JUL2010
4 cycle2day1 19JUL2010
5 cycle2day12 30JUL2010
6 cycle2day26 12AUG2010
7 cycle3day26 09SEP2010
8 cycle4day26 06OCT2010
777 END OF TREATMENT 09NOV2010
999 UNSCHEDULES VISIT 14OCT2010
RUN;
Want to create a new variable visit2 based on condition:
data vsn_srt;
set vsn_srt;
if vstname ^= "UNSCHEDULED VISIT" then visit2=visit1;
/*retain _visit2;*/
run;
After code execuetion the dataset should look like this :
visit2 visit1 vstname vst1dtc
1 1 Baseline 06JUL2010
2 2 cycle1day1 12JUL2010
4 4 cycle2day1 19JUL2010
5 5 cycle2day12 30JUL2010
6 6 cycle2day26 12AUG2010
7 7 cycle3day26 09SEP2010
8 8 cycle4day26 06OCT2010
8 999 UNSCHEDULES VISIT 14OCT2010
777 777 END OF TREATMENT 09NOV2010
SO NEED TO CARRY FORWARD THE PREVIOUS VALUE(8) IN VISIT2 VARIABLE
based on condition unschedules visit the rest values is visit2=visit1
thanks!
You're almost there:
data vsn_srt;
set vsn_srt;
if vstname ^= "UNSCHEDULED VISIT" then visit2=visit1;
retain visit2;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.