Desktop productivity for business analysts and programmers

Date Prompt

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

Date Prompt

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


Accepted Solutions
Solution
‎01-06-2017 10:47 AM
PROC Star
Posts: 1,146

Re: Date Prompt

 

 

 

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


All Replies
Solution
‎01-06-2017 10:47 AM
PROC Star
Posts: 1,146

Re: Date Prompt

 

 

 

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

 

 

Super User
Posts: 5,368

Re: Date Prompt

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

 

%let dated_ym = &dated_year.&dated_month.;

Contributor
Posts: 45

Re: Date Prompt

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).

Contributor
Posts: 45

Re: Date Prompt

Oups sorry I know, I just forgot the double-quotes Smiley Frustrated

 

Sorry for this.

PROC Star
Posts: 1,146

Re: Date Prompt

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

 

Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 293 views
  • 2 likes
  • 3 in conversation