BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data div;
input value $;
datalines;
40/20
150/30
300/100
;
run;

data dd;
set div;
result=mod(input(value,value,best12.));
proc print;
run;

 How to divide values 

5 REPLIES 5
Tom
Super User Tom
Super User

It is not clear what you are trying to do.

What output would you expect from that input.

Also explain what real world situation would require that you do anything like this?

BrahmanandaRao
Lapis Lazuli | Level 10
40/20 =2
Tom
Super User Tom
Super User

So convert the string into two pieces, convert the substrings into numbers, divide the numbers.

result = input(scan(value,1,'/'),32.) / input(scan(value,2,'/'),32.);
mkeintz
PROC Star

Reading from a raw file?  Then use DLM='/' (assuming you always expect a division sign):

 

data want;
  infile datalines dlm='/';
  input numerator denominator;
  quotient=numerator/denominator;
datalines;
40/20
150/30
300/100
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
FreelanceReinh
Jade | Level 19

Maybe evaluate the expression to a numeric value and then continue from there:

data want;
set div;
nvalue=input(resolve(cats('%sysevalf(',value,')')),32.);
run;

KSharp used this RESOLVE-%SYSEVALF technique in several of his posts (e.g., here in 2011; in 2012 he mentioned that he himself learned it "from this Forum").

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1106 views
  • 4 likes
  • 4 in conversation