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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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?

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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?

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 302 views
  • 0 likes
  • 3 in conversation