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;
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?
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?
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.