I have following table;
data Table1;
input product $ start_date :date7. end_date:date7. Price;
format start_date end_date date9.;
datalines;
p1 01Jan17 18Jan18 15
p1 19Jan18 15Jul18 30
p1 16Jul18 31Mar19 24
p2 08Jan17 31Dec17 17
p2 01Jan18 15Mar18 19
p2 26Jul18 31Mar19 18
;
i want to run following codes on this tables:
proc tabulate data=Table1;
var start_date end_date;
table start_date end_date,
n nmiss (min max median)*f=mmddyy10. range;
run;
in var and table option I am choosing variable manual, I want this code to choose all date variable itself.
i.e. I don't need to mentioned date variable myself, program should choose all the variable in date format and run this code on date variable only.
The challenge here is that SAS doesn't have a data type of DATE and though the only way to identify columns with SAS date values is via the SAS format applied.
Below code demonstrates the approach. You will have to add more SAS Date format names in order to make this more generic.
data Table1;
input product $ start_date :date7. end_date:date7. Price;
format start_date end_date date9. other_dttm datetime20.;
other_dttm=datetime();
datalines;
p1 01Jan17 18Jan18 15
p1 19Jan18 15Jul18 30
p1 16Jul18 31Mar19 24
p2 08Jan17 31Dec17 17
p2 01Jan18 15Mar18 19
p2 26Jul18 31Mar19 18
;
proc sql noprint;
select name into :col_list separated by ' '
from dictionary.columns
where libname='WORK' and memname='TABLE1'
and upcase(format) like 'DATE%'
and upcase(format) not like 'DATETIME%'
;
quit;
proc tabulate data=Table1;
var &col_list;
table &col_list,
n nmiss (min max median)*f=mmddyy10. range;
run;
I've been hoping that function FMTINFO() could make this task a bit simpler but the function didn't even recognise DATE7. as a date format with my rather recent version of SAS.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: