Help using Base SAS procedures

Get month value in sas macro

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Get month value in sas macro

Hello all,

          i am going to read a file name thats like B11_20110926_DeliverStatus.csv

          i am able to collect the date by substring the file using the following code:

%substr(B11_20110926_DeliverStatus.csv,4,8);

          but i am unable to get the MONTH of the substring's file.

          is that possible to convert the 20110926 to a sas datetime format?

          i try to get the date by using following code.

          is that still anyway to do so?

Regards:

Liangck


Accepted Solutions
Solution
‎09-29-2011 04:15 AM
Super User
Posts: 5,441

Get month value in sas macro

Isn't %substr(B11_20110926_DeliverStatus.csv,9,2); working for you?

You can use the macro function %sysfunc, whic let's you use (almost) any SAS function within a macro context:

%let sasdate = %sysfunc(inputn(%substr(B11_20110926_DeliverStatus.csv,5,8),yymmdd8.));

/Linus

Data never sleeps

View solution in original post


All Replies
Solution
‎09-29-2011 04:15 AM
Super User
Posts: 5,441

Get month value in sas macro

Isn't %substr(B11_20110926_DeliverStatus.csv,9,2); working for you?

You can use the macro function %sysfunc, whic let's you use (almost) any SAS function within a macro context:

%let sasdate = %sysfunc(inputn(%substr(B11_20110926_DeliverStatus.csv,5,8),yymmdd8.));

/Linus

Data never sleeps
Occasional Contributor
Posts: 16

Get month value in sas macro

%let sdate=20061212;

%let ndate=%sysfunc(inputn(&sdate,yymmdd10.));

%let nmonth=%sysfunc(month(&ndate));

%put _user_;

Contributor
Posts: 21

Get month value in sas macro

Linus Randy Dai:

          Thank you both, i tried both answer and i got got the result perfectly.

          thanks, apperciate alot.

Regards

Liangck

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 2101 views
  • 3 likes
  • 3 in conversation