BookmarkSubscribeRSS Feed
chirumalla
Calcite | Level 5

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

3 REPLIES 3
Patrick
Opal | Level 21

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

Jagadishkatam
Amethyst | Level 16

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
data_null__
Jade | Level 19

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 420 views
  • 0 likes
  • 4 in conversation