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

I'm having trouble inputting recid data into SAS. Here is my first 10 lines of code:

data recid;
   input id$ week arrest$ fin$ age race$ wexp$ mar$ paro$ prio educ$;
   cards;
1       20      1       0       27      1       0       0       1	3	3
2       17	1	0	18	1	0	0	1	8	4
3	25	1	0	19	0	1	0	1	13	3
4	53	0	1	23	1	1	1	1	1	5
5	53	0	0	19	0	1	0	1	3	3
6	53	0	0	24	1	1	0	0	2	4
7	23	1	0	25	1	1	1	1	0	4
8	53	0	1	21	1	1	0	1	4	3
9	53	0	0	22	1	0	0	0	6	3
10	53	0	0	20	1	1	0	0	0	5
;
run;

The output, however, ends up looking like this

 

      id    week    arrest    fin    age    race    wexp    mar    paro    prio    educ

1    1      20          1         0      27      1          0          0       1 3 3     2     17 1 01 

 

What's going on here?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Looks like you have a tab as a delimiter instead of spaces? Or fixed width possibly?

Try adding this lines and seeing if it helps:

infile cards dlm='09'x DSD TRUNCOVER;

This will tell SAS the delimiter is a tab. FYI - you're reading in numeric data as a character in some places (educ, paro) is that what you want to do?

View solution in original post

3 REPLIES 3
Reeza
Super User
Looks like you have a tab as a delimiter instead of spaces? Or fixed width possibly?

Try adding this lines and seeing if it helps:

infile cards dlm='09'x DSD TRUNCOVER;

This will tell SAS the delimiter is a tab. FYI - you're reading in numeric data as a character in some places (educ, paro) is that what you want to do?
westbestern
Obsidian | Level 7
the infile statement worked perfectly!! thank you! and yes, educ and paro are both categorical variables.
Reeza
Super User

Categorical doesn't mean they need to be character. 

In fact, if you want them to sort and have them as a character, it'll sort alphabetically, ie 1, 10, 11, 12 while numbers will sort correctly. 

 

You can use formats to apply any descriptive labels and the CLASS statement will take both numeric/character variables when you need to specify variables as categorical. 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 378 views
  • 1 like
  • 2 in conversation