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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

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