PROC FORMAT Question

Reply
Super Contributor
Posts: 1,040

PROC FORMAT Question

Hi,

I have used proc format in the past and have a wired question...

I want to know what happens if I don't put the other in the proc format?????

as u can see I used "other" in $origin and not in the $origin...............and I am using those two formats on the same variable

automatically doesn't it get set to missing? do we have to use OTHER????

Thanks

value $orign

/*'EO','RA','1'='1'*/

/*'OP','OS','2'='2'*/

'TH','4'='4'

/*'NB','NP','NS',*/'TE','TI',/*'25',*/'5','24'='5'

/*'NE',*/'RB','TB','TF','TP','TR','TS','TT','TU','TV','TW','6','18'/*,'26'*/='6'

other=" "

;

value $orignB

'25', 'NS', 'NP', 'NB'='5'

'NE', '26'='6'

;

NB04=put(Code,$orign.);

if TYPE=4 then NB04=put(Code,$orignB.);

Grand Advisor
Posts: 10,210

Re: PROC FORMAT Question

Generally if you do not use an OTHER assignment then the original value will be displayed. If numeric that may be in a BEST type format. I think if your format is character and you assign a default length shorter than "other" values they could be truncated to the length of the setting in the format.

Super Contributor
Posts: 1,040

Re: PROC FORMAT Question

Hi Ballard,

Thanks for the reply

If I have properly understood you then:

In my example above" if I did not use "Other "u meant : what ever is the CODE value will be put into NB04.....even if I didn't say so????????

CODE

24

25

26

27

28

29

value $orign

'24', '25','26'='4'

'27'='5'

;

run;

NB04=put(Code,$orign.);

NB04 has a value of 28 and 29 where CODE is 28 and 29?????

Thanks

Esteemed Advisor
Posts: 7,293

Re: PROC FORMAT Question

As long as you use a format of $orign2.  Otherwise I think they will appear as 2 and 2 rather than 28 and 29.

Super Contributor
Posts: 1,040

Re: PROC FORMAT Question

Hi Art,

Thanks for the reply.

I did not clearly understand. Could you show an example so that I would better understand???

Thanks

Esteemed Advisor
Posts: 7,293

Re: PROC FORMAT Question

proc format;

value $orign

'24', '25','26'='4'

'27'='5'

;

run;

data have;

  input CODE $;

  format code $orign2.;

  cards;

24

25

26

27

28

29

;

Super Contributor
Posts: 1,040

Re: PROC FORMAT Question

I was thinking so far  if I am creating a new variable(UBO4) like shown below and then put the resultant in that variable after applying the format........

28 and 29 would not come there into the UBO4 column.....even if you give a length of how much ever to the format.

I was thinking there would be a blank in UBO4 column corresponding to the 28 and 29 in the ID column!!!!!!!!since we did not assign anything to it........it seems clearly that is bringing the ID values (original values) for which ever format doesn't get applied????

But it seems clearly that it is wrong!!!!

proc format;

value $orign

'24', '25','26'='AA'

'27'='BB'

;

run;

data have;

  input CODE $;

  cards;

24

25

26

27

28

29

;

data want;
set have;
UBO4=put(Code,$orign.);
run;

Grand Advisor
Posts: 10,210

Re: PROC FORMAT Question

That's exactly the behavior I mentioned earlier: if you don't have an "other" then the original value is the result of the format. If you want a blank then use an other= ' ' statement in your format.

Ask a Question
Discussion stats
  • 7 replies
  • 261 views
  • 0 likes
  • 3 in conversation