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

I am self learning SAS and am stuck in a very basic Issue.

Kindly refer to the code:

data work.empsal1;
set work.empsal;
if salary < 20000 then PAYBAND = "LOW" ;
ELSE IF 20000 <= SALARY < 30000 THEN PAYBAND = "MEDIUM";
ELSE PAYBAND = "HIGH";
RUN;

The values in the PAYBAND column is appearing as 'LOW', 'MED', 'HIG'

How to fix It.

It is very basic issue but as I have no direct tutor I cannot solve it. Plz help.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

after the SET statement, you need a LENGTH statement to specify the maximum length of the variable. If you don't it sets the length by the length of the first time the variable is assigned a value.

 

length payband $ 6;
--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

after the SET statement, you need a LENGTH statement to specify the maximum length of the variable. If you don't it sets the length by the length of the first time the variable is assigned a value.

 

length payband $ 6;
--
Paige Miller
Reeza
Super User

@avijit_p wrote:

 

It is very basic issue but as I have no direct tutor I cannot solve it. Plz help.


 People get direct tutors?

ballardw
Super User

A very important part of SAS is the Format of variable. The format displays desired text and for almost all of the analysis procedures will use the formatted values for categories. The very fun part is that you can create formats as needed. That will allow you to create multiple displays or analysis from the same variable without having to create multiple variables as long as you only need one category set per procedure for a given variable.

Consider:

 

 

proc format library=work;
value payband
low   - < 20000 = 'LOW'
20000 - < 30000 = 'MEDIUM'
30000 - HIGH   = 'HIGH'
;
value alpayband
0  - < 20000 = 'LOW'
20000 - < 30000 = 'MEDIUM'
30000 - < 50000 = 'Higher'
50000 - High = 'HIGHEST'
;

run;

proc freq data=work.empsal;
   tables salary;
   format salary payband.;
run;

proc freq data=work.empsal;
   tables salary;
   format salary altpayband.;
run;
Reeza
Super User

The first SAS e-course is free and covers topics like this. There's also 

video.sas.com -> How To>  Analytics U

http://video.sas.com/#category/videos/sas-analytics-u

 

Lots of videos that cover these topics.

avijit_p
Calcite | Level 5

Thanks a lot.

The videos would of a great help.

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
  • 6 replies
  • 7187 views
  • 2 likes
  • 4 in conversation