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. 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1003 views
  • 1 like
  • 2 in conversation