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

Data Practice_PFormat;
Input Fname $ Lname $ Title Salary grade $;
cards4;
Henry Ford 1 25000 A
Greg Robert 2 35000 B
John Smith 3 40000 D
Henry Will 4 45000 F
Kile Jason 5 50000 I
;;;;
run;

proc format;
value NTitle
1='AM'
2='M'
3-5='SM';

value $Ngrade
'A'='Good'
'B'='Fair'
;
run;

data practice_pformat;
set practice_pformat;
format title ntitle. grade ngrade.;
run;

 

After writing the code above, i am not able to assign grades to my table Practice_PFormat

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

That code you have posted works fine for me in a clean SAS session, and I get the correct results.  Therefore I would suggest that either 1) Your data does not actually look like the example you give - maybe you have a space before the value? or 2) your format is not being written to the file, or loaded correctly, maybe there is already a format called that existing and you can't overwrite.  I would suggest starting a fresh session, pasting the code you present here into your new session and running it, as it looks fine to me, so something else is at fault.

View solution in original post

7 REPLIES 7
ballardw
Super User

How are you attempting to assign grades to the table? Do you get an error or unexpected results.

 

Also, your format statement should be:

format title ntitle. grade $ngrade.;

as you have declared the format to be character. This could be an issue if you ever have character and numeric formats with the same name.

 

 

saurabhvrm
Calcite | Level 5
Data Practice_PFormat;
Input Fname $ Lname $ Title Salary grade $;
cards4;
Henry Ford 1 25000 A
Greg Robert 2 35000 B
John Smith 3 40000 D
Henry Will 4 45000 F
Kile Jason 5 50000 I
;;;;	
run;

proc format;
value NTitle
1='AM'
2='M'
3-5='SM';

value $Ngrade
'A'='Good'
'B'='Fair'
'C'-'F'='Poor'
'I'='Fail'
;
run;

data practice_pformat;
set practice_pformat;
format title ntitle. grade $ ngrade.;
run;

I have updated the code above, for anyone getting a grade from 'c' to 'f' the grade should get get updated to "Poor", but after running the code, the output still shows the grade as d,f,i for john,henry,kyle respectively. Snapshot attached


Capture.PNG
Reeza
Super User

Are you using SAS UE? Check the forum for a note, I think there's some know issues with formats within SAS UE and they provide the workarounds. It was posted this week.

 

 

It works fine on my machine (SAS 9.3 Base).

 

FreelanceReinh
Jade | Level 19

It really looks like the bug described in Problem Note 57730. (Cf. also this recent post.)

RW9
Diamond | Level 26 RW9
Diamond | Level 26

That code you have posted works fine for me in a clean SAS session, and I get the correct results.  Therefore I would suggest that either 1) Your data does not actually look like the example you give - maybe you have a space before the value? or 2) your format is not being written to the file, or loaded correctly, maybe there is already a format called that existing and you can't overwrite.  I would suggest starting a fresh session, pasting the code you present here into your new session and running it, as it looks fine to me, so something else is at fault.

saurabhvrm
Calcite | Level 5

thank you so much everyone, it was a problem of format existing already, i thought it should be overwritten when i run the code again.

worked correctly in a new session.

FreelanceReinh
Jade | Level 19

@saurabhvrm wrote:

... i thought it should be overwritten when i run the code again.

 

Indeed, it should be overwritten. That's what the bug Reeza and I mentioned consists in.

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
  • 7 replies
  • 735 views
  • 0 likes
  • 5 in conversation