BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Machan69
Calcite | Level 5

Hello, I think I posted same question before but not sure where my topic went. I'm a new sas user using sas studio, I hope you can help me with my journey.

Q:I was looking to create a sas data set with 3 columns: name,gender,age from this text file that looks like the one below. I'm having trouble because it's not just delimited but some of the columns i need is all in one column in the txt file. whenever i do the proc import step i get a data set with column name with everything under it.

mark
m_21
ash
m_18
bumi
f_36
bambam
f_36
bacon
f_23
bona
f_23
bingo
m_36
lena
f_18

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

"Import" is the wrong verb for the action you need to do.  You just need to READ the text file.

 

Let's take your sample lines and convert it to a file so we have something to code against.

options parmcards=text ;
filename text temp;
parmcards;
mark
m_21
ash
m_18
bumi
f_36
bambam
f_36
bacon
f_23
bona
f_23
bingo
m_36
lena
f_18
;

Now let's write a data step that will read NAME from one line and GENDER and AGE from the next.

data want;
  infile text dlm='_' truncover ;
  input name $30.  / gender :$1. age ;
run;

Results:

Tom_0-1678570189823.png

 

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

"Import" is the wrong verb for the action you need to do.  You just need to READ the text file.

 

Let's take your sample lines and convert it to a file so we have something to code against.

options parmcards=text ;
filename text temp;
parmcards;
mark
m_21
ash
m_18
bumi
f_36
bambam
f_36
bacon
f_23
bona
f_23
bingo
m_36
lena
f_18
;

Now let's write a data step that will read NAME from one line and GENDER and AGE from the next.

data want;
  infile text dlm='_' truncover ;
  input name $30.  / gender :$1. age ;
run;

Results:

Tom_0-1678570189823.png

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 704 views
  • 2 likes
  • 2 in conversation