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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

4 REPLIES 4
LinusH
Tourmaline | Level 20

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

Data never sleeps
ballardw
Super User

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

robertrao
Quartz | Level 8

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;

Ksharp
Super User

Use QUOTED when DischargeDispositionkey is character .

whereas , NO QUOTED for numeric .

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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