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.
There is only one value in each observation, so there is nothing to expand it with.
@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?
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.
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;
not giving the desired result. I have run the code below is the output:
I want a variable full_name as anushka sharma etc..
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.
Thankyou So much for your help 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.