i have the below data:
subj | asdt | svsstd_num | flag |
101 | 2006-01-10 | 28-dec-05 | Y |
102 | 2005-11-15 | 12OCT2005 | Y |
102 | 2005-12-08 | 07-nov-05 | Y |
103 | 2006-01-05 | 02-dec-05 | Y |
the svsstd_num date format ias 12OCT2005 however i am not able to make it in excel. but all the date in svsstd_num is the same format.
I am using the below code;
data ae051;
set ae98;
svsstd_num=input(SVSTDTC,yymmdd10.);
format svsstd_num date9.;
if visit="Visit 2 (Baseline)" then do;
if ASTDT < svsstd_num then flag= "N";
else flag= "Y";
end;
run;
which is taking if visit is in visit2 then flag, but if we see the second observation the flag should be "N".
I am not sure why it is not giving the right result.
I am suer we have mentioned this several times previously. Post your test data in the form of a datastep. Follow this post if you don't know how to.
It is very important to show dataset structure as this also has a bearing on programming. I would suspect, from what you have posted that astdt is character, and that will be less than the numeric date value (i.e. convert the string into ascii numbers, will be less than number of days since..).
Also, several other things mentioned before, use the code editor window - {i} or SAS run symbol to keep formatting on code, e.g:
data ae051; set ae98; svsstd_num=input(svstdtc,yymmdd10.); format svsstd_num date9.; if visit="Visit 2 (Baseline)" then do; if astdt < svsstd_num then flag="N"; else flag="Y"; end; run;
Note, visit is not in your test data, but I assume that check works fine.
attached is the sample dataset which i was trying and the code below
data ani(keep=svsstd_num visit ASTDT flag);
set ae98;
svsstd_num=input(SVSTDTC,yymmdd10.);
format ASTDT svsstd_num date9.;
if visit="Visit 2 (Baseline)" then do;
if ASTDT < svsstd_num then flag = "N";
else flag = "Y";
end;
run;
Oh.My.God.
What is so hard to understand about this:
"Please post correct example data in a data step, so we don't have to type it ourselves."
Now I have to download the .zip, unpack it, copy the file to my SAS server, only to find out that my SAS can't open it because of version problems. Probably because you run a DBCS SAS.
With a data step, a simple copy/paste from here to the EG code window would have sufficed.
Are you intentionally rude, or just lazy, or what?
Your example data does not match the data you use in the data step. Variable visit is missing, and astdt should probably be asdt.
Please post correct example data in a data step, so we don't have to type it ourselves.
Also always post the log of the step that gives you problems.
For the flag portion, look at this (I added an additional observation to test the case for "N"):
data have;
input subj asdt :yymmdd10. svsstd_num :date9.;
format asdt svsstd_num yymmdd10.;
cards;
101 2006-01-10 28-dec-05
102 2005-11-15 12OCT2005
102 2005-12-08 07-nov-05
103 2006-01-05 02-dec-05
104 2006-01-05 06-jan-06
run;
data want;
set have;
if ASDT < svsstd_num
then flag = "N";
else flag = "Y";
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.