BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

I have the following codes, may i know how to get the following remarks?

 

Any idea? Thanks.


data a;
input staff house car;
cards;
1234 1 0
2234 5 1
3234 2 2
;
run;

 

Desired result

 

Staff   Remarks

1234  1 house and 0 car

2234  5 house and 1 car

3234  2 house and 2 car

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

This is fairly simple to do in SAS. But I have to ask why you want a variable with a much more complicated string containing information that you already have in your dataset? 🙂

Shmuel
Garnet | Level 18

All you need is to concatenate the given data with some literals:

 

data want;

  set have;

        remarks = catx(' ',staff,'house and',car,'car');

      /* or:  remarks = left(staf) || ' house and ' || left(car) || ' car';  */

run;

ChrisBrooks
Ammonite | Level 13

This is the simplest way

 

data a;
input staff house car;
cards;
1234 1 0
2234 5 1
3234 2 2
;
run;

data b(drop=house car);
	length staff 8 remarks $17;
	set a;
	remarks=cat(house,' house and ',car,' car');
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1445 views
  • 0 likes
  • 4 in conversation