BookmarkSubscribeRSS Feed
Srigyan
Quartz | Level 8

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.

1 REPLY 1
Patrick
Opal | Level 21

@Srigyan 

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. 

Capture.JPG

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 1 reply
  • 583 views
  • 0 likes
  • 2 in conversation