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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1 reply
  • 819 views
  • 0 likes
  • 2 in conversation