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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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