BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sg_kr
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

6 REPLIES 6
andreas_lds
Jade | Level 19

Import as two variables, then use a cat-function to create the required value in a new variable.

sg_kr
Obsidian | Level 7

thank you, but any other way except this.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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;
muratatik
Obsidian | Level 7

 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;
sg_kr
Obsidian | Level 7
Thanks for your reply.
but the data is to be import from a sheet and now enclosed in " ".

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
  • 6 replies
  • 2276 views
  • 0 likes
  • 5 in conversation