the lenght of pstn = 25
Thanks, you provided the macro in the code box.
However it would really help if you read and followed the rest of the instructions. We don't need the 50 or so lines of the log before %create_ipay_pct9 is called. We're trying to help you, but you have to help us.
MPRINT(CREATE_IPAY_PCT9): data ipay_pct9_2202504 (keep=pstn area nmbr vl); MPRINT(CREATE_IPAY_PCT9): set ipay_pct9202504; MPRINT(CREATE_IPAY_PCT9): if country not in (' ') or wert not= . then do; MPRINT(CREATE_IPAY_PCT9): pstn = "(PCT2)"; MPRINT(CREATE_IPAY_PCT9): end; MPRINT(CREATE_IPAY_PCT9): run; NOTE: Variable country is uninitialized. NOTE: Variable wert is uninitialized.
The macro fails because in the &input data set, there is no variable named COUNTRY and no variable named WERT, so SAS doesn't know what to do. In essence, this isn't a macro error, it is a BASE SAS error, you can't use variable names that don't exist in the data set.
Which brings up a discussion of "best practice" when writing macros. First you need to create code that works without macros and without macro variables, for one possible set of values if input, output and pstn_value. It appears you have not done that. Had you done that, you could fix that code and get it to work before writing the macro, based on working code. You need to do that and show us the working code without macros and without macro variables.
options mprint; /* Makro zur Erstellung von PCT-Daten */ %macro create_ipay_pct9(input, output, pstn_value); data &output (keep=pstn area nmbr vl); set &input; if area not in (' ') or vl not= . then do; pstn = "&pstn_value"; end; run; %mend create_ipay_pct9; %create_ipay_pct9(ipay_pct9&year.&month, ipay_pct9_2&year.&month, PCT.2);
Thanks for pointing out the error in the macro. I've corrected the error and now it works as it should.
Hi,
Congratulations on working code - I assume the truncation issue was resolved too. It's good to see your code posted in a code box.
I would further suggest you mark @PaigeMiller's post as the solution, as that identified the (one of the) problem(s) - and all from the benefit of sharing the log.
Thanks & kind regards,
Amir.
@Hoibai wrote:
How can I pass an alphanumeric value with a dot (e.g., PST.2) to a macro? Thanks.
Dots (aka periods) do not normally cause any trouble for the macro processor.
The only place is when want to place a period immediately after the value of a macro variable reference. In your case if you wanted the value of PST to come from a macro variable named PREFIX you might try to use:
&prefix.2
But that will not work because the macro processor uses the period to mark the end of the macro variable name. In this case so that it knows the macro variable is named PREFIX and not PREFIX2. So to get the period into the value you need to include a second period.
&prefix..2
That character that does cause trouble with macro calls is the comma. That is because the macro processor uses comma to delimit the parameter values being passed. If you need to pass in a comma to a macro call you will need to mask it some how. One easy way is to design the macro to expect the value to have actual quotes around it.
%macro mymac(input,output,value);
data &output;
set &input;
name = &value ;
run;
%mend;
%mymac(sashelp.class,class,"Smith, Sam");
Note that the quotes are part of the value.
You could also use ( ) to mask the value, again the ( ) will be part of the value.
%macro mymac2(input,output,value);
data &output;
set &input;
where name in &value ;
run;
%mend;
%mymac2(class,class2,("Alfred","Smith, Sam"));
And finally you could use macro quoting.
%quote(Smith, Sam)
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.