PNPTestovir
PNPTestovir

Reputation: 307

Reading comma values

How to read below data in SAS?

Yellowstone           ID/MT/WY 1872 *  4,065,493
Everglades            FL 1934 *        1,398,800
Yosemite              CA 1864 *          760,917
Great Smoky Mountains NC/TN 1926 *       520,269
Wolf Trap Farm        VA 1966 *              130

For last column I only get:

406549
1
.
520
.

Code:

data math;
    input 
        parkname $ 1-22
        state $
        year
        asteriks $
        value COMMA9.;
    datalines;
Yellowstone           ID/MT/WY 1872 *  4,065,493
Everglades            FL 1934 *        1,398,800
Yosemite              CA 1864 *          760,917
Great Smoky Mountains NC/TN 1926 *       520,269
Wolf Trap Farm        VA 1966 *              130
;

proc print data=math;
run;

Upvotes: 0

Views: 44

Answers (1)

kl78
kl78

Reputation: 1666

Your problem is that the spaces after the * are also counted for the numbers, so if you have 9 spaces the number is empty, 8 spaces you get only first number, and so on...

EDIT:

Googled a bit and found a lot easier solution. Adding a & tells sas to ignore multiple blanks, so

value & COMMA9.;

should fix this problem the easiest way, at least it did in your testprogram.

EDIT END

Easiest solutions I can think of would be to remove all spaces except one after *, or add another delimiter (# for example) or increase the the size of value:

 Yellowstone           ID/MT/WY 1872 * 4,065,493
 Everglades            FL 1934 * 1,398,800

or

data math;
infile datalines delimiter='#'; 
 ...
Yellowstone#ID/MT/WY#1872#*#4,065,493
...

or

value COMMA20.;

Upvotes: 2

Related Questions