Help using Base SAS procedures

Stuck on Proc Format Issue - Please Help!

Accepted Solution Solved
Reply
Super Contributor
Posts: 259
Accepted Solution

Stuck on Proc Format Issue - Please Help!

Below is an extract from a dataset i use to convert to a format library. I have another data set which calls the format library later on in the code. Basically, the other data set contans details of the vehicle age of the policy and I use the put (vehicle age, format name) function to find the label that corresponds to the vehicle age. So if the vehcile age is 1 and the product is AAA, the put function returns a value the letter A.

.

TableNameProductStartEndLabel
DRVAGEAAA02A
DRVAGEAAA26B
DRVAGEAAA610C
DRVAGEBBB02A
DRVAGEBBB26B
DRVAGEBBB610C
...............

Since the label depends both on the table name and the product I convert the above table into the table below and create a format library based on this table:

FMTNAMEStartEndLABEL
DRVAGEAAA02A
DRVAGEAAA26B
DRVAGEAAA610C
DRVAGEBBB02A
DRVAGEBBB26B
DRVAGEBBB610C

usin the code...

Data dataset1;

set dataset;

fmtname = tablename||product;

keep fmtname start end label;

run;

proc format cntlin = dataset1; fmtlib; run;

This works fine so I have my format library.

The problem is where I want to execute the put statement so that my dataset with the policy info pulls in the label from this table. If there was only one product, say AAA, then the code;

data policydata1;

set policy data;

vehiclageband = put(vehicleage, drvageaaa.);

run;

works fine.

However, there are many products and I want the code to be able to be dynamic with regard to the product. The product field in the policy dataset is called 'product' so I want the code to be dynamic, I tried:

data policydata1;

set policy data;

vehicleageband = put(vehicleage, "drvage"||product.)

run;

But this returns errors. Does anyone have a way around this? I've been searching the internet for ages.


Accepted Solutions
Solution
‎05-26-2014 11:43 AM
Super User
Posts: 19,872

Re: Stuck on Proc Format Issue - Please Help!

Change the put to putn in your example and use catt instead of ||

If you still can't get it to work let me know and I'll post an example.

vehicleageband = putn(vehicleage, catt("drvage", product))

View solution in original post


All Replies
Super User
Posts: 19,872

Re: Stuck on Proc Format Issue - Please Help!

Look at the putc/putn functions instead.

EDIT: Also make sure your concatenation isn't introducing extra spaces so trim or use the appropriate cat function, such as CATT.

Super Contributor
Posts: 259

Re: Stuck on Proc Format Issue - Please Help!

Hi Reeza

Would you be able to give an example of how it would be used in this scenario?

Basically, the code works when I put in the code:

data policydata1;

set policydata;

vehicleagebad = put(vehicleage,drvageaaa.)  -> (the drvagaaa. is highlighted in green)

But I want to replace the aaa in the expression to a dynamic variable that varies depending on the product, so if the product is aaa, it will look up drvageaaa; if it's bbb, it will look up drvagebbb, and so on.

The product is a field in the policydata dataset.

Thanks

Solution
‎05-26-2014 11:43 AM
Super User
Posts: 19,872

Re: Stuck on Proc Format Issue - Please Help!

Change the put to putn in your example and use catt instead of ||

If you still can't get it to work let me know and I'll post an example.

vehicleageband = putn(vehicleage, catt("drvage", product))

Super Contributor
Posts: 259

Re: Stuck on Proc Format Issue - Please Help!

Thank you very much, that worked!

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 193 views
  • 1 like
  • 2 in conversation