@Kurt_Bremser, Sry, but I must ask again:
your code inspired me, thank you. But ive noticed, that the code doesnt work and I dont know why. Can you help me once more? 🙂
The structure:
First: The User shall enter the years and quarters that are neccessary:
/* Year1:*/
%let year1=2019;
/*Year2*/
%let Year2=2020;
/*Which quarter shall be involved? */
%let Quarter2="1","2","3","4";
Afterwards, the dataset gets filtered with the entered data:
Data want;
set have;
where (Year="&Year2." or Year="&Year1.") and Quarter in(&quarter2.);
run;
That works. Now, the call symput command follows:
data _null_;
call symputx ("quarter_final", ifc(indexc(&Quarter2.,"4"),"4","1"));
run;
My interpretation: If the macro "quarter2" contains the "4" (for example: "2","3","4"), the macro called "quarter_final" should produce the "4". If not (for example ["1","2","3"], it produces the "1". Thats what I want.
Based on this, the next data-step should use the population-value of the quarter "4". But it doesnt. Why? Where is the error in my code?
Data want2;
set want;
if year="&year2." and Quarter="&Quarter_final." and Region="1" then population_2 = population;
run;
PS:I also tried it with the apostroph like below:
data _null_;
call symputx ("quarter_final", ifc(indexc("&Quarter2.","4"),"4","1"));
run;
...but it produces an error:
""1","2","3","4"
__ ___ ___
49 49 49
___
49
_
388
_
76
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
ERROR 388-185: Expecting an arithmetic operator.
ERROR 76-322: Syntax error, statement will be ignored.
Thank you for helping again!
Edit:
If I enter only the "4", the macro produces the the "4"; thats correct.
If i enter the "4" in combination with an other digit (for example "1","4"), I got the "1". Thats not correct. It actually has to produce the "4", cause the 4 is one of the entered information.
... View more