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

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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