BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
madara155
Obsidian | Level 7

Hi

I have a SAS date as a macro variable as follows:

%let Date_selected = 01Feb2022

I want to extract the month as a two digit no from this.

(eg: FEB => month_no = 02,

       Mar => month_no = 03,

       Apr => month_no = 04

etc).

With SYMPUTX I can get the month as a digit but not in 2 digit format.

call symputx("month_no",put("&Date_selected"d,month.)); /*this gives month_no = 2*/

Can someone help me with this?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Why call symputx?

%let Date_selected = 01Feb2022;
%let m = %sysfunc(month("&date_selected."d), z2.);

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Try this

 

%let Date_selected = 01Feb2022;

data _null_;
   m = put(month("&Date_selected"d), z2.);
   call symputx('m', m);
run;

%put &m.;
andreas_lds
Jade | Level 19

Why call symputx?

%let Date_selected = 01Feb2022;
%let m = %sysfunc(month("&date_selected."d), z2.);
madara155
Obsidian | Level 7

Thank you very much 🙏 You saved my life 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3383 views
  • 1 like
  • 3 in conversation