BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
azhar7860
Obsidian | Level 7

    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;

 

                   Capture.PNGCapture_2.PNG

 

 

 

will apprecaite any inputs

 

Thansk

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
4 REPLIES 4
Kurt_Bremser
Super User

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.

azhar7860
Obsidian | Level 7

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!

           

azhar7860
Obsidian | Level 7
Thanks Awesome!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1123 views
  • 1 like
  • 2 in conversation