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

Hi,

 

I want to create a new variable that contains dates less than 9/1/2022; but for the life of me, I can not get the following statement to work. Thanks in advance for your help.

 

data Work.Quest_Results_2;
Set Work.Quest_Results_2;
term1 = input(terminationdate, mmddyy10.);
format term1 mmddyy10.;
run;


Data Work.Quest_Results_3;
set Work.Quest_Results_2;
if term1 le '01Sep2022'd then termed = term1;
else termed = "";

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Is your Terminationdate variable text? If so, what does it look like?

 

There is chance that this code:

data Work.Quest_Results_2;
Set Work.Quest_Results_2;

on a previous pass has corrupted or lost data. Using the same data set for input and output completely replaces the original data set.

 

Your use of Termed is mixing numeric, the value of hopefully a date value in Term1 and character with e termed = ""; Assign missing values to numeric variable with  termed = . ; or just not even bother to execute the Else.

 

What does your log look like?

View solution in original post

4 REPLIES 4
ballardw
Super User

Is your Terminationdate variable text? If so, what does it look like?

 

There is chance that this code:

data Work.Quest_Results_2;
Set Work.Quest_Results_2;

on a previous pass has corrupted or lost data. Using the same data set for input and output completely replaces the original data set.

 

Your use of Termed is mixing numeric, the value of hopefully a date value in Term1 and character with e termed = ""; Assign missing values to numeric variable with  termed = . ; or just not even bother to execute the Else.

 

What does your log look like?

Jesusismygrace
Obsidian | Level 7
Thank you!
Tom
Super User Tom
Super User

DATE values are numeric. So use a numeric missing value, not a character string.  Or use the CALL MISSING() function.

data Work.Quest_Results_3;
  set Work.Quest_Results_2;
  term1 = input(terminationdate, mmddyy10.);
  termed = term1;
  if termed > '01SEP2022'd then call missing(termed);
  format term1 termed YYMMDD10. ;
run;

Are you trying to do a censored survival analysis?

In that case it might be better to use a truncated date instead of setting the later dates to missing.

data Work.Quest_Results_3;
  set Work.Quest_Results_2;
  term1 = input(terminationdate, mmddyy10.);
  censored = term1 > '01SEP2022'd ;
  termed = min(term1,'01SEP2022'd);
  format term1 termed YYMMDD10. ;
run;

PS Displaying dates in MDY or DMY order will confuse 50% of your audience. Display them using YMD order or the DATE format to avoid confusing May First for the Fifth of January.

Jesusismygrace
Obsidian | Level 7
Thank you for the example!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 489 views
  • 2 likes
  • 3 in conversation