read only date part from data set name

Reply
Contributor
Posts: 41

read only date part from data set name

Hi,

I have 50+ data sets having different lengths with date extension, I want to read only date part from data sets and store in a variable for time stamp.

pls advise me how to read date part from data set name.

TEST_201312.sas7bdat

TEST__MONTH_201312.sas7bdat

TEST__YEAR_201312.sas7bdat

Respected Advisor
Posts: 3,892

Re: read only date part from data set name

USE scan() with delimiter _.  and -2 as counter so extracting second last substring.

Trusted Advisor
Posts: 1,129

Re: read only date part from data set name

Please try the below code

data TEST_201312;

test=1;

run;

data TEST__MONTH_201312;

test=1;

run;

data TEST__YEAR_201312;

test=1;

run;

proc  sql;

  create table tab as select memname, cats(put(input(substr(left((compress(memname,,'kd'))),5,2),best.),monname3.),substr(left((compress(memname,,'kd'))),1,4)) as month_year  from dictionary.tables where upcase(memname) like "TEST%";

quit;

output:

Thanks,

Jag

Thanks,
Jag
Respected Advisor
Posts: 3,777

Re: read only date part from data set name

Where do want the new variable to go?  You seem to imply you want the new variable in each data set.

Ask a Question
Discussion stats
  • 3 replies
  • 224 views
  • 0 likes
  • 4 in conversation