Not able to assign format

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Not able to assign format

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


Accepted Solutions
Solution
‎03-24-2016 01:30 PM
Super User
Super User
Posts: 7,401

Re: Not able to assign format

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


All Replies
Super User
Posts: 10,500

Re: Not able to assign format

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.

 

 

New Contributor
Posts: 3

Re: Not able to assign format

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
Super User
Posts: 17,837

Re: Not able to assign format

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).

 

Trusted Advisor
Posts: 1,115

Re: Not able to assign format

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

Solution
‎03-24-2016 01:30 PM
Super User
Super User
Posts: 7,401

Re: Not able to assign format

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.

New Contributor
Posts: 3

Re: Not able to assign format

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.

Trusted Advisor
Posts: 1,115

Re: Not able to assign format


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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 393 views
  • 0 likes
  • 5 in conversation