BookmarkSubscribeRSS Feed
Sikcion
Fluorite | Level 6

 

Hi guys! I am doing one sdtm project question,

there is one variable "folder" to keep the visiting week values like "week1" "screening" "week5";  also, we want to create a new variable "visitnum" to extract the numbers of folder, like if folder=week5, so we keep 5 for the visitnum;

when the folder="SRV", we want to keep the previous value of visitnum; like for observation80, we have folder="SRV", so we keep the previous obs(79) visitnum=43, and we get the visitnum=43+0.01;

I am trying to use RETAIN and lag function to keep the previous value, I don't know why the prev_visit value is correct, but the visitnum is keep the previous 2 value +0.01? like for the observation when prev_visit=43,  I hope to get visitnum=43.01 not 36.01.

Screenshot 2023-12-14 at 2.50.17 AM.png

Can you help me to fix it? Thank!

 

data vs_vs3;
set vs_vs2;
retain prev_visit;
length visit $14;
if first.vetest then prev_visit=.;

if folder="SCREENING" then do;
visitnum= -1;
visit="Screening";
end;

else if index(upcase(folder),"WEEK") then do;
visitnum= substr(folder,5)*7-6;
visit="Screening";
end;

else if index(upcase(folder),"SRV") then do;
visitnum = prev_visit +0.01;
visit="Systemic"||"-"||strip(put(visitnum,best12.));
end;

else if index(upcase(folder),"UNS")then do;
visitnum = prev_visit +0.01;
visit="Unsched"||"-"||strip(put(visitnum,best12.));
end;
prev_visit = lag(visitnum);
*drop prev_visit;
run;

1 REPLY 1
Kurt_Bremser
Super User

I don't see the folder variable in your picture.

Do not post data in pictures. Post data as text, ideally in a DATA step with DATALINES. Use the "little running man" button to post code, it will keep the original formatting (which is eaten by the main posting window).

As long as we do not have usable data to work with (we can't copy/paste a picture into the program editor), it is hard to help you.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 449 views
  • 0 likes
  • 2 in conversation