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!
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.
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.
Thanks it was indeed easier to solve from the grid, submerged in the problem didn't look into the simplest solution!.
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!
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.