Hi <
i have 3 columns like below.
Name age sex
kalyan,reddy,27,M
Goutham,reddy,28,M
i want to import the name kalyan,reddy & goutham,reddy under column Name.
Thanks in advance
Wrap up the input line from the back end:
data want;
input;
length
name $50
age 8
sex $1
;
nwords = countw(_infile_,',');
sex = scan(_infile_,-1,',');
age = input(scan(_infile_,-2,','),best.);
do i = 1 to nwords - 2;
name = catx(',',name,scan(_infile_,i,','));
end;
drop i nwords;
cards;
kalyan,reddy,27,M
Goutham,reddy,28,M
;
run;
Import as two variables, then use a cat-function to create the required value in a new variable.
thank you, but any other way except this.
The import program needs to have a logical method of reading the data. It does this by having a delimiter. In your case the delimiter is used within the data, hence you have the choices:
enlcose the data which has the delimiter within quotes
change the delimier to something which does not appear in the data
import the data as is and post process the data
There is no other logical way of identifying data which may or may not be part of the same variable.
Wrap up the input line from the back end:
data want;
input;
length
name $50
age 8
sex $1
;
nwords = countw(_infile_,',');
sex = scan(_infile_,-1,',');
age = input(scan(_infile_,-2,','),best.);
do i = 1 to nwords - 2;
name = catx(',',name,scan(_infile_,i,','));
end;
drop i nwords;
cards;
kalyan,reddy,27,M
Goutham,reddy,28,M
;
run;
You can use infile and dsd options. But your name variable sould be in quote marks.
data want;
infile datalines dsd dlm=",";
input Name :$15. age sex $;
datalines;
'kalyan,reddy',27,M
'Goutham,reddy',28,M
;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.