Hi SAS experts,
I'm new to SAS programming, could you please help with the following!
I've multiple date columns for a study and some of these date columns can be completely empty for all the rows, so while importing, SAS is importing these completely empty columns as length 1 characters. Since other dates are imported as dates and I'm not able to compare across these dates.
My sample data looks like this
id,date1,date2,date3 100,,, 101,10-10-2020,20-10-2020, 102,15-10-2020,, 103,,,
I'm trying to import this using
proc import out= test
datafile = "/home/one/sas/study_data.txt"
dbms = CSV REPLACE ;
delimiter=',';guessingrows=32767;
DATAROW=2;
run;
In the imported data, I'm seeing the date3 as character of length 1, so I'm not able to compare this date3 column with date2
Is there a way, we can tell SAS to import all the date columns (date1, date2, date3) as date columns of format YYMMDD10. even though some of these columns are completely empty and if the column isn't empty, it should import all the data in the format YYMMDD10.
Thanks a ton in advance!!
You say it yourself: all the rows are blank for the variable. So what's to compare.
Copy the code generated by proc import that will be in the log. Paste into the editor and clean up. Change the informat to match that of the "date" variables you do see.
If you are reading multiple similar files then a data step is a much better way to go. That way you set all the properties for the variables and can make them the same for different data sets. Just change the name of the source file on the INFILE statement and the name of the output data set.
You say it yourself: all the rows are blank for the variable. So what's to compare.
Copy the code generated by proc import that will be in the log. Paste into the editor and clean up. Change the informat to match that of the "date" variables you do see.
If you are reading multiple similar files then a data step is a much better way to go. That way you set all the properties for the variables and can make them the same for different data sets. Just change the name of the source file on the INFILE statement and the name of the output data set.
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.