Help using Base SAS procedures

Proc Format, convert format to values

Reply
N/A
Posts: 1

Proc Format, convert format to values

Hello

Is there a way to change the bands I have created via Proc Format to real values?

Ie I have a variable Price ranging from 1 - 100 and have used Proc Format to display it as A:1 - 10, B:10 - 20 etc

I want to merge this dataset to another one with the same format applied. Currently my merge wont match value 8 with format A:1 - 10 to value 7 wirth format A:1 - 10. Is there a way to make that happen?

Thanks
Super Contributor
Super Contributor
Posts: 3,174

Re: Proc Format, convert format to values

Create your own SAS variable to use with the MERGE/BY processing - assign a SAS CHARACTER type variable using the SAS PUT function with your "source" variable a argument1 and the user SAS format name as argument2.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

data step put function user format site:sas.com
Regular Contributor
Posts: 241

Re: Proc Format, convert format to values

...
> Is there a way to change the bands I have created via
> Proc Format to real values?
>
> Ie I have a variable Price ranging from 1 - 100 and
> have used Proc Format to display it as A:1 - 10, B:10
> - 20 etc
>
> I want to merge this dataset to another one with the
> same format applied. Currently my merge wont match
> value 8 with format A:1 - 10 to value 7 wirth format
> A:1 - 10. Is there a way to make that happen?

First, if you attach a format to a variable, you are not changing the values at all, they just look different when displayed or printed out. You can create a new variable storing the formatted values of your original variable. Then you can use the new variable to further manage your data. Or you can just temporarily do that, if the execution efficiency is not your first priority. Here is one way using proc sql. hth.

[pre]
/* test format and datasets */
proc format;
value price 1-10="A" 10-20="B";
run;

data one;
v1 = 1; price = 8; output;
v1 = 2; price = 13; output;
format price price.;
run;

data two;
v2 = 10; price = 7; output;
v2 = 20; price = 15; output;
v2 = 30; price = 16; output;
run;

/* join one and two based on formatted price. notice
that you have to pass the format name as a literal in
calling the putn function */
proc sql;
create table three as
select v1, v2, one.price as price1,
two.price as price2 format = price.
from one, two
where putn(one.price, "price") = putn(two.price, "price");

/* check */
select * from three;
quit;
/* on lst
v1 v2 price1 price2
------------------------------------
1 10 A A
2 20 B B
2 30 B B
*/
[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 151 views
  • 0 likes
  • 3 in conversation