Is anyone can help with this data set ??
I'm a starter on SAS.
Thank you in advance.
LEE ATHNOS
1215 RAINTREE CIRCLE
PHOENIX AZ 85044
HEIDIE BAKER
1751 DIEHL ROAD
VIENNA VA 22124
MYRON BARKER
131 DONERAIL DRIVE
ATLANTA GA 30363
JOYCE BENET
85 MAPAVENUE
MENLO PARK CA 94025
Reading data from multiple lines is not an issue as such. The challenge with the data you've posted is that we don't know what's on which line - so for example when does a new address start.
Does your data contain anything additional to what you've posted - eg. at the beginning of the line some sort of an indicator value telling us if the line contains the name, the street address and so on?
Thank you for the reply Patrick.
I believe the first line contains field of Fname and Lname;
the second line contains field of Address (with street name and number) ;
the third line contains field of city, state and zipcode.
I wrote the code as such :
data info;
infile "/folders/myfolders/SAS Practice.txt";
input #1 Fname:$6. Lname :$6.
#2 Address : $21.
#3 City : $10. State :$2. Zipcode;
run;
But the result only showed number on the address , and incomplete city.
Could you tell me where it went wrong? Thanks.
Two issues (one small, one large).
First, remove the colons for ADDRESS and CITY. That's what stops the INPUT statement when it hits a blank, rather than reading the full 21 (or the full 10) characters.
Second, the third line will be much more difficult to work with because some city names contain two words instead of one. You could read the entire line as one long variable, then count the number of words in it to determine which piece(s) go into which variables.
Because a City can be 2 words, you won't be able to do a straight read for line 3. Unless you have two spaces between your other fields which is unlikely in the real world. If this is a class room example it may.
You'll need to read the line in as one string and then parse it. Parse it out backwards, last field is zip, second last is state and the remaining is city.
Are you sure you're using the Colon correctly here? I don't think you need it in all cases. It's used to read text with embedded blanks. Would that be true with First/Last Name?
This gets things in, I'll leave the parsing of the final line to you.
data info;
informat fname lname $15.;
input #1 Fname $ Lname $
#2 Address $30.
#3 String3 $30.;
cards;
LEE ATHNOS
1215 RAINTREE CIRCLE
PHOENIX AZ 85044
HEIDIE BAKER
1751 DIEHL ROAD
VIENNA VA 22124
MYRON BARKER
131 DONERAIL DRIVE
ATLANTA GA 30363
JOYCE BENET
85 MAPAVENUE
MENLO PARK CA 94025
;
run;
According to:
the input statement can be written also as:
INPUT fname $10 lname $10 / address $30 / strung3 $30;
The / tells SAS to continue on next line.
Modify your data step like this:
data info;
infile "/folders/myfolders/SAS Practice.txt" truncover;
input Fname:$6. Lname :$6.;
input Address $30.;
input city_state_zip $100.;
length city $30 state $2;
words = countw(city_state_zip);
zipcode = input(scan(city_state_zip,words),best.);
state = scan(city_state_zip,words-1);
do i = 1 to words - 2;
city = catx(' ', trim(city),scan(city_state_zip,i));
drop i;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: