Hi,
I'm trying to set a macro variable called i using an existing variable in my dataset (which is numeric).
%let i = %sysfunc(inputn(var1, 3.));
The problem is that some records have var1 as correctly missing. I don't want those records to go through the macro I've set up anyway, but no matter how I try to set it up to run the macro conditionally, I'm getting error messages which indicate that SAS is trying to use the missing values of var1.
This is an example of something I tried:
%macro one;
if var1 ne . then do;
%let i = %sysfunc(inputn(var1, 3.));
end;
%mend;
%one;
I also tried
data want;
set have;
if var1 ne . then do;
%one;
end;
run;
I thought that since the records where var1 is missing did not meet the if criteria, they would not be run through the macro and cause the error messages, but that has not been the case.
Any help is appreciated.
In a datastep use call symputx to create a macro variable
In an open code or macro definition, you could use %let . I hope you understand the macro compile time operation?
In a datastep use call symputx to create a macro variable
In an open code or macro definition, you could use %let . I hope you understand the macro compile time operation?
Your macro code doesn't make any sense.
You are using %SYSFUNC() to call the INPUTN() function. As the value for inputn() to read you are passing in the constant text var1. Because you are using the informat of 3. the function is going to try and read just the first three of those characters, var, as a number. That will always return a missing value.
To access the value a variable named var1 you would need to use actual SAS code, not macro code.
What is it that you want to do in your data step?
Once you figure that out then you can think about whether or not you need to use any macro statements.
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.