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

Below I have the results of the macros that I have created. 

%put &alldates1.;


'02/22/2021', '02/23/2021', '02/25/2021', '02/26/2021', '03/01/2021'

 

%put &alldates2.;
'02/22/2021' '02/23/2021' '02/25/2021' '02/26/2021' '03/01/2021'

I want to make edits to the macros to look like this without having to type them out or make edits to each item on the list:

 

%put &alldates1.;

'02/22/2021'N, '02/23/2021'N, '02/25/2021'N, '02/26/2021'N, '03/01/2021'N

 

%put &alldates2.;

'02/22/2021'N '02/23/2021'N '02/25/2021'N '02/26/2021'N '03/01/2021'N

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

It would probably be easier to generate the N when you make the macro variables.

But a call to TRANWRD() should do it.

%let have='02/22/2021', '02/23/2021', '02/25/2021', '02/26/2021', '03/01/2021';
%let want=%sysfunc(tranwrd(%superq(have),%str(,),%str(N,)))N ;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

It would probably be easier to generate the N when you make the macro variables.

But a call to TRANWRD() should do it.

%let have='02/22/2021', '02/23/2021', '02/25/2021', '02/26/2021', '03/01/2021';
%let want=%sysfunc(tranwrd(%superq(have),%str(,),%str(N,)))N ;
judyluu
Calcite | Level 5

works perfectly! 

For learning purposes I was wondering how to have it in the list before the macro is created.

 

proc sql;
select distinct quote(strip(DueDate)," ' ")
into: alldates1 separated by ','
from Pivot1;
quit;

 

This is what I did to create the macro list. I was able to figure out how to add the quotes, but I am not too sure how to add the "N".

 

Thanks again!

Tom
Super User Tom
Super User

Just include in the column you are selecting into the macro variable. Also add NOPRINT so your listing is not cluttered with the list of values.

proc sql noprint
select distinct cats(quote(strip(DueDate),"'"),'N')
  into :alldates1 separated by ','
  from Pivot1
;
quit;

Are you really trying to create a dataset with variable names that look like date strings? You could also use the NLITERAL() function to add the quotes and N when needed.

nliteral(DueDate)

Of if DueDate really has some leading spaces you want removed:

nliteral(left(DueDate))

Why not just keep the dataset in a natural format and produce such a "table" as a REPORT and not a DATASET.  PROC REPORT or PROC TABULATE can easily use the value of DATE variable as the header for a column in the report it produces.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 590 views
  • 1 like
  • 2 in conversation