BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

What is the correct way to create this data set.

Sometimes there are long spaces between items and I dont want  to change it manually.

I know that for each variable there should be only one item (or one word only)

 


Data Longtbl;
input ID field $  labelField $  category $ ;
cards;
1 x1      Team a
1 x2 smoker y
1 x3  status	1
2 x1 Team b
2 x2 smoker	n
2 x3 status	2
3 x1 Team c
3 x2 smoker	n
3 x3 status	2
4 x1 Team a
4 x2 smoker	n
4 x3 status	3
5 x1 Team b
5 x2 smoker	y
5 x3 status	1
6 x1 Team a
6 x2 smoker	y
6 x3 status	1
7 x1 Team c
7 x2 smoker	y
7 x3 status	2
8 x1 Team a
8 x2 smoker	n
8 x3 status	2
9 x1 Team a
9 x2 smoker	y
9 x3 status	3
;
run;
2 REPLIES 2
Shmuel
Garnet | Level 18

The delimiter in your data is sometimes space '20'x and sometimes tab '09'x or both.

To read the the data ceorrectly I have added an INFILE statement with appropriate options:

Data Longtbl;
infile cards dlm='2009'x truncover;
input ID field $  labelField $  category $ ;
cards;
1 x1      Team a
1 x2 smoker y
1 x3  status	1
2 x1 Team b
2 x2 smoker	n
2 x3 status	2
3 x1 Team c
3 x2 smoker	n
3 x3 status	2
4 x1 Team a
4 x2 smoker	n
4 x3 status	3
5 x1 Team b
5 x2 smoker	y
5 x3 status	1
6 x1 Team a
6 x2 smoker	y
6 x3 status	1
7 x1 Team c
7 x2 smoker	y
7 x3 status	2
8 x1 Team a
8 x2 smoker	n
8 x3 status	2
9 x1 Team a
9 x2 smoker	y
9 x3 status	3
;
run;
Shmuel
Garnet | Level 18
You can check delimiters using notepad++ or msword and brows with view-all symbols.

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
  • 2 replies
  • 689 views
  • 0 likes
  • 2 in conversation