SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

I want to create a new variable called X_new that will get following values:

IF x>=5000 and X<6000 then X_new=5000

IF X>=6000 then x_new will be the the round up by 1000 value

so expected values of x_new are:

X=5100 x_new=5000

X=5902 x_new=5000

X=7812 x_new=8000

X=12210 x_new=13000

X=5988 x_new=6000

X=7102 x_new=8000

X=7980 x_new=8000

What is the way to do it please?

 

 

Data tbl;
input ID X;
cards;
1 5100
2 5902
3 7812
4 12210
5 5988
6 7102
7 7980
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ronein
Meteorite | Level 14
Data ttt;
input ID X;
cards;
1 5100
2 5902
3 7812
4 12210
5 5988
6 7102
7 7980
;
run;

data ttt2;
set ttt;
IF x>=5000 and X<6000 then X_new=5000;
else x_new=1000*ceil(x/1000);
Run;

View solution in original post

1 REPLY 1
Ronein
Meteorite | Level 14
Data ttt;
input ID X;
cards;
1 5100
2 5902
3 7812
4 12210
5 5988
6 7102
7 7980
;
run;

data ttt2;
set ttt;
IF x>=5000 and X<6000 then X_new=5000;
else x_new=1000*ceil(x/1000);
Run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 517 views
  • 0 likes
  • 1 in conversation