Proc frormat question

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

Proc frormat question

Hi,

'DischargeDispositionkey' variable  was initially numeric
i am trying to apply the below formats to the 'DischargeDispositionkey' variable and after applying I want the DISP variable created to remain numeric with a lenght of 3.
To my surprise when i use DISP=put(DischargeDispositionkey,dispkey.); I am getting the result but DISP is now a charecter variable....How can that happen ?even after I wrote a numeric format(without quotes and without $sign in front of the format name???

Secondly, it throws an error if itry to use
DISP=input(DischargeDispositionkey,dispkey.);

Please suggest?


proc format;

value dispkey
0,2,13,15,24,27,41,54,55,60,61,65,72,75,76,87,99,100,101,104,110,115,121,127=1
3,6,10,12,16,26,58,59,62,73,77,80,84,86,90,98,105,108,111,116,119,122=2
4,31,45,78,106,117=3
5,47,79,96,107,118=4
14,18,19,20,21,22,23,30,32,33,34,36,38,39,40,44,48,49,51,52,53,56,74,88,92,93,94,95,97,102,103,112,113,114,123,124,125,126=5
7,9,17,25,28,29,37,42,43,50,81,83,91,109,120=6
8,35,46,82=7
11,57,63,64,66,67,68,69,70,71,85,89=20

;
run;

DISP=put(DischargeDispositionkey,dispkey.);


Accepted Solutions
Solution
‎07-07-2015 07:05 PM
Grand Advisor
Posts: 10,253

Re: Proc frormat question

DISP=input(put(DischargeDispositionkey,dispkey.),best.);

OR make an informat

proc format;

invalue dispkey
0,2,13,15,24,27,41,54,55,60,61,65,72,75,76,87,99,100,101,104,110,115,121,127=1
3,6,10,12,16,26,58,59,62,73,77,80,84,86,90,98,105,108,111,116,119,122=2
4,31,45,78,106,117=3
5,47,79,96,107,118=4
14,18,19,20,21,22,23,30,32,33,34,36,38,39,40,44,48,49,51,52,53,56,74,88,92,93,94,95,97,102,103,112,113,114,123,124,125,126=5
7,9,17,25,28,29,37,42,43,50,81,83,91,109,120=6
8,35,46,82=7
11,57,63,64,66,67,68,69,70,71,85,89=20

;
run;

before using:

DISP=input(DischargeDispositionkey,dispkey.);

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,202

Re: Proc frormat question

Put always creates a character result, input can create a numerical result.

Data never sleeps
Solution
‎07-07-2015 07:05 PM
Grand Advisor
Posts: 10,253

Re: Proc frormat question

DISP=input(put(DischargeDispositionkey,dispkey.),best.);

OR make an informat

proc format;

invalue dispkey
0,2,13,15,24,27,41,54,55,60,61,65,72,75,76,87,99,100,101,104,110,115,121,127=1
3,6,10,12,16,26,58,59,62,73,77,80,84,86,90,98,105,108,111,116,119,122=2
4,31,45,78,106,117=3
5,47,79,96,107,118=4
14,18,19,20,21,22,23,30,32,33,34,36,38,39,40,44,48,49,51,52,53,56,74,88,92,93,94,95,97,102,103,112,113,114,123,124,125,126=5
7,9,17,25,28,29,37,42,43,50,81,83,91,109,120=6
8,35,46,82=7
11,57,63,64,66,67,68,69,70,71,85,89=20

;
run;

before using:

DISP=input(DischargeDispositionkey,dispkey.);

Super Contributor
Posts: 1,040

Re: Proc frormat question

Thanks for the reply.

Also is it incorrect to put in quotes while writing formats for numeric variables????

OR it doesn't matter if we put or not

/*QUOTED VALUES*/

proc format;

invalue dispkey
'0','2','13','15','24','27'=1

run;

Vs.

/*NO QUOTES */

proc format;

invalue dispkey
0,2,13,15,24,27=1

run;

Grand Advisor
Posts: 9,596

Re: Proc frormat question

Use QUOTED when DischargeDispositionkey is character .

whereas , NO QUOTED for numeric .

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 217 views
  • 6 likes
  • 4 in conversation