BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have two datasets gender and stage and common variable called category.
But in the gender dataset this variable has got a format gender where as in the other dataset the same variale has different format called stage.
But when I am setting these two datasets, SAS takes format from the first dataset only and applies the same format for the values in the other dataset.
But I want to retain the formatted values in both datasets when I am concatenating two datasets. How can I achieve this?
2 REPLIES 2
Olivier
Pyrite | Level 9
If I understand well, you concatenate the two datasets with a SET statement. The common variable had different formats in the separate datasets, is that correct ?
You cannot have two formats on a single variable, depending on the observation. But what you can do is create a character variable, using a PUT statement that will apply the correct format depending on the origin of the observation.
Something like :[pre]
DATA work.concat ;
SET work.gender (IN = in_gender) work.stage (IN = in_stage) ;
IF in_gender THEN char_var = PUT(category, gender.) ;
ELSE char_var = PUT(category, stage.) ;
RUN ;
[/pre]
Regards
Olivier
LinusH
Tourmaline | Level 20
You can store the formatted value in a seperate column, something like this:

data genderstage;
set gender (in=g) stage (in=s);
if g then gendFmt = put(gender,$gendFmt.)
else gendFmt = put(gender,$stageFmt.);
run;

Regards,
Linus
Data never sleeps

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 697 views
  • 0 likes
  • 3 in conversation