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

Please see below the data (from a dat file) I am trying to read. I know that I need to use @@ to read the file but for some reason I am unable to do this through my program. please note that

 

Since the first variable (Name) has two words separated by an space, I used column format to read this variable. However, the way the data is, it is causing other issues.  When I don't put double trailing, I get just the first four rows on the left and when I apply @@ the program would run indefinitely .

 

 

Data

Robin                  S    28   41 Bald Eagle  R 102 244 Barn Owl    R 50 110

Osprey                R   66 180 Cardinal      S    23   31 Goldfinch   S  11   19

Golden Eagle      R 100 234 Crow           S    53 100 Magpie      S  60    90

Elf Owl                R   15   27 Condor        R 140  300

 

 

Program

data bird;
infile '/folders/myfolders/MyRawData/Birds.dat';
input Name $1-13 Jungle $ Min Max @@;
run;

 

 
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

As long as you always have more than one space after the name, you can use the ampersand modifier:

 

data bird;
*infile '/folders/myfolders/MyRawData/Birds.dat';
length name $20 jungle $1;
input Name & Jungle Min Max @@;
datalines;
Robin                  S    28   41 Bald Eagle  R 102 244 Barn Owl    R 50 110
Osprey                R   66 180 Cardinal      S    23   31 Goldfinch   S  11   19
Golden Eagle      R 100 234 Crow           S    53 100 Magpie      S  60    90
Elf Owl                R   15   27 Condor        R 140  300
;

 

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

As long as you always have more than one space after the name, you can use the ampersand modifier:

 

data bird;
*infile '/folders/myfolders/MyRawData/Birds.dat';
length name $20 jungle $1;
input Name & Jungle Min Max @@;
datalines;
Robin                  S    28   41 Bald Eagle  R 102 244 Barn Owl    R 50 110
Osprey                R   66 180 Cardinal      S    23   31 Goldfinch   S  11   19
Golden Eagle      R 100 234 Crow           S    53 100 Magpie      S  60    90
Elf Owl                R   15   27 Condor        R 140  300
;

 

PG
awais
Obsidian | Level 7

brilliant. learned something new today i.e. & modifier. Do you know the difference between & modifier and : modifier?

 

thank you for your help,

 

Awaos

PGStats
Opal | Level 21

Both are features of list directed input. : reads the next token and then applies an informat to that token. & defines the next token as everything until more than one space is encountered. The two modifiers can be combined.

PG
Tom
Super User Tom
Super User

I kind of looks like you have at least 13 characters for the name. Why not just use a format to read the name?

data bird;
  input Name $13. Jungle $ Min Max @@;
*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8;
cards;
Robin         S   28   41 Bald Eagle    R  102  244 Barn Owl      R   50  110
Osprey        R   66  180 Cardinal      S   23   31 Goldfinch     S   11   19
Golden Eagle  R  100  234 Crow          S   53  100 Magpie        S   60   90
Elf Owl       R   15   27 Condor        R  140  300
;

But it is really hard to see what you file looks like when you paste it into the body of you question (without using the pop-ups that preserve formatting) because the forum editor thinks you are typing paragraphs and not only uses a non-fixed width font but can remove spaces and end of lines.