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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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.

brophymj
Quartz | Level 8

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

Reeza
Super User

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

brophymj
Quartz | Level 8

Thank you very much, that worked!

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
  • 4 replies
  • 774 views
  • 1 like
  • 2 in conversation