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

Hi,

 

I am using SA Enterprise Guide and I have a user choice date in parameter which I called "dated", and is from this type: "06/01/2017".

 

I created three macro variable following this:

%let dated_year = %sysfunc(year("&dated."d));
%let dated_month = %sysfunc(month("&dated."d));
%let dated_ym = %sysfunc(cats(&dated_year, &dated_month));

 

First question:

when i put dated_year is correct: "2017".

But when I put dated_month, it's written "1" instead of "01"...it's not very important for dated_month but more problematic for dated_ym which is "20171" instead of "201701".

Do you know how I should do?

 

Second question:

I want to format these three macro variable in character, but I don't know how to do it. Do you have an idea?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

 

 

 

1, You can use formats to zero-fill your numbers, like this

 

%let dated_month = %sysfunc(putn(%sysfunc(month("&dated."d)), z2.));

 

2. Macro variables are always character strings, so you shouldn't have any problem. Can you describe what you're trying to do in a little more detail?

 

Tom

 

 

View solution in original post

5 REPLIES 5
TomKari
Onyx | Level 15

 

 

 

1, You can use formats to zero-fill your numbers, like this

 

%let dated_month = %sysfunc(putn(%sysfunc(month("&dated."d)), z2.));

 

2. Macro variables are always character strings, so you shouldn't have any problem. Can you describe what you're trying to do in a little more detail?

 

Tom

 

 

Astounding
PROC Star

Also note, once you have implemented Tom's solution, the last statement can be simplified:

 

%let dated_ym = &dated_year.&dated_month.;

Planck
Obsidian | Level 7

Thanks for both of you.

 

I can accept only one topic as a solution, but you both helped me... for the first question.

 

For the second:

I try to do something like that:

 

PROC SQL;
CREATE TABLE A
(DA_IN char(6));

INSERT INTO A values (&dated_ym.);
QUIT;
RUN;

 

And I got this.

Value 1 of VALUES clause 1 does not match the data type of the corresponding column in the object-item list (in the SELECT
clause).

Planck
Obsidian | Level 7

Oups sorry I know, I just forgot the double-quotes :S

 

Sorry for this.

TomKari
Onyx | Level 15

If it's not a semicolon I'm missing, it's a double quote!!

 

Smiley Happy

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 5 replies
  • 4133 views
  • 2 likes
  • 3 in conversation