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;
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
;
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
;
brilliant. learned something new today i.e. & modifier. Do you know the difference between & modifier and : modifier?
thank you for your help,
Awaos
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.