DATA Step, Macro, Functions and more

Create a new variable with custom text

Reply
Contributor scb
Contributor
Posts: 69

Create a new variable with custom text

[ Edited ]

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

 

PROC Star
Posts: 754

Re: SAS Query

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? Smiley Happy

Trusted Advisor
Posts: 1,570

Re: SAS Query

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;

Super Contributor
Posts: 440

Re: SAS Query

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;
Ask a Question
Discussion stats
  • 3 replies
  • 99 views
  • 0 likes
  • 4 in conversation