BookmarkSubscribeRSS Feed
poojasv20
Calcite | Level 5

I have one dataset there is only one variable name.

Name

anushka

sharma

priyanka

chopra

alia

bhatt

 

I want a full name in different variable. How to do that in SAS.

7 REPLIES 7
andreas_lds
Jade | Level 19

@poojasv20 wrote:

I have one dataset there is only one variable name.

...

I want a full name in different variable. How to do that in SAS.


This is impossible. Where should the names come from?

 

EDIT: Is the first name in the first obs and the last name in the next obs?

poojasv20
Calcite | Level 5

Yes . it is like first name in the first obs and the last name in the next obs.

and how can we get the full name.

Kurt_Bremser
Super User
data want;
set have;
length full_name $40;
retain full_name;
if full_name > ""
then do;
  full_name = catx(" ",full_name,name);
  output;
  full_name = "";
end;
else full_name = name;
keep full_name;
run;
poojasv20
Calcite | Level 5

not giving the desired result. I have run the code below is the output:

poojasv20_0-1652774820781.png

I want a variable full_name as anushka sharma etc..

Kurt_Bremser
Super User

Then you haven't run my code, or you provided wrong data, or you failed to adapt the code to your data (different variable/dataset names).

Proof:

data have;
input name :$10.;
datalines;
anushka
sharma
priyanka
chopra
alia
bhatt
;

data want;
set have;
length full_name $40;
retain full_name;
if full_name > ""
then do;
  full_name = catx(" ",full_name,name);
  output;
  full_name = "";
end;
else full_name = name;
keep full_name;
run;

proc print data=want noobs;
run;

Result:

full_name
anushka sharma
priyanka chopra
alia bhatt

As you were told in the welcome mail you got when registering here, you must (MUST) provide example data in usable form (in a data step with datalines) to get tested code. Otherwise we have to make guesses.

poojasv20
Calcite | Level 5

Thankyou So much for your help 🙂 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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