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

Hello all,

I have an input dataset, an example of which looks like:

data have;

input var1;

cards;

4

45

100

101

145

200

201

256

345;

run;

I want to create another variable (say, Batch) based on the criteria: if var1=1 to 100 then Batch=1, var1=101 to 200 then Batch=2, etc.

For this dataset, I can do this using this code:

data out; set  have;

if var1<=100 then batch=1;

else if var1<=200 then batch=2;

else if var1<=300 then batch=3;

run;

But if the actual values of var1 get bigger (say 3040) that would involve writing too many else if's. Also, the values of var1 could go up or down, so will not know in advance how many else if statements I would need. Once I determine the maximum value of var1 (say, MaxVar1), please could you suggest how to calculate the variable Batch.

Many thanks.

VD

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Divide by 100, then round upwards to the next integer

batch=ceil(var1/100);

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Divide by 100, then round upwards to the next integer

batch=ceil(var1/100);

--
Paige Miller
VD
Calcite | Level 5 VD
Calcite | Level 5

Thank you!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 790 views
  • 0 likes
  • 2 in conversation