BookmarkSubscribeRSS Feed
vraj1
Quartz | Level 8

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.

 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

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.

vraj1
Quartz | Level 8

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;

Kurt_Bremser
Super User

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?

Kurt_Bremser
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 4 replies
  • 817 views
  • 0 likes
  • 3 in conversation