BookmarkSubscribeRSS Feed
SAS_inquisitive
Lapis Lazuli | Level 10

Hello,

 

This  example code was taken from stackoverflow.

 

data have;
input MERCH_NO      V01   M02  V08  M08  AMOUNT    PLAN $;
calc = input(vvaluex(plan),best12.) * amount;
put calc=;
datalines;
123456        2     2    1    1    100.00    V01     
456789        4     4    4    4    250.00    M08    
;;;;
run;

 

 

Can vvaluex be regarded as kind of macro variable resolution? In this example, value of V01 is 2.

 

I replicated the outout with this code.

 

%let V01 = 2;
%let M08 = 4;
data test;
set have;
calc= input(symget(plan),best.)*amount;
run;

3 REPLIES 3
Reeza
Super User

@SAS_inquisitive wrote:

 

 

Can vvaluex be regarded as kind of macro variable resolution? In this example, value of V01 is 2.

 


No. VVALUEX returns the value of a variable. It can have nothing to do with macro variables. 

 

You create macro variables but don't use them so your example doesn't quite make sense.

SAS_inquisitive
Lapis Lazuli | Level 10

@Reeza wrote "You create macro variables but don't use them so your example doesn't quite make sense".

 

I am creating those macro variables and using symget function to get values. Basically, I was trying to do same thing as vvaluex function does using symget in this example.

Tom
Super User Tom
Super User

If you know your macro variable(s) contain numeric strings (all macro variables are character strings) you can use the SYMGETN() function to read it directly into a numeric variable and skip the INPUT() function call.

 

%let V01 = 2;
%let M08 = 4;
data want;
  input plan $ amount ;
  calc= symgetn(plan)*amount;
cards;
V01 3.4
M08 4.5
;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1881 views
  • 2 likes
  • 3 in conversation