BookmarkSubscribeRSS Feed
Gemgem
Calcite | Level 5
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
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
chang_y_chung_hotmail_com
Obsidian | Level 7
...
> 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]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1989 views
  • 0 likes
  • 3 in conversation