DATA Step, Macro, Functions and more

vvaluex

Reply
Regular Contributor
Posts: 234

vvaluex

[ Edited ]

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;

Super User
Posts: 17,840

Re: vvaluex


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.

Regular Contributor
Posts: 234

Re: vvaluex

@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.

Super User
Super User
Posts: 6,500

Re: vvaluex

[ Edited ]

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
;

 

Ask a Question
Discussion stats
  • 3 replies
  • 99 views
  • 2 likes
  • 3 in conversation