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

The sql procedure below (within a macro) generates a macro variable 'imp_date'

 

%macro imp_test;


/* List of runs as macro variable */
proc sql noprint;
select cats(year(date),put(month(date),z2.)) into :imp_date separated by ' '
from grid
where flag_qtr = 1 and date >= "&gen_date_first."d and date <= "&gen_date_last."d;
quit;

 

[...]

 

%mend

 

,where gen_date_first=31MAR2018, gen_date_last=31DEC2020.

 

output:

IMP_DATE = 201803 201806 201809 201812 201903 201906 201909 201912 202003 202006 202009 202012

 

Now I need to remove '202003' from imp_date, and tried with

imp_date_test = remove(imp_date,9);

before quit; within the sql procedure and got error: 'Statement is not valid or it is used out of proper order'. 

 

Guessed I was not using the right function for the type of 'imp_date' but also got an error after adding the two lines below (before quit;😞

 

type_imp_date = type(imp_date);

%put &=type_imp_date;

 

Can you please suggest the right way to do remove '202003' from imp_date and finding the type for imp_date?.

 

Thanks in advance!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Would it not make more sense to find the 9th element of data set GRID and work from there, instead of first creating and then working with a long macro variable?

 

Also, please, from now on, when you get an error in the LOG, show us the LOG for this PROC or DATA step. Do not show us error messages in the log that are disconnected from rest of the log and disconnected from the code that created them.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Would it not make more sense to find the 9th element of data set GRID and work from there, instead of first creating and then working with a long macro variable?

 

Also, please, from now on, when you get an error in the LOG, show us the LOG for this PROC or DATA step. Do not show us error messages in the log that are disconnected from rest of the log and disconnected from the code that created them.

--
Paige Miller
maryami
Calcite | Level 5

Thanks it was indeed easier to solve from the grid, submerged in the problem didn't look into the simplest solution!.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 508 views
  • 0 likes
  • 2 in conversation