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

Hello SAS Community!

 

I need to split the address column into two new columns, City and ZipCode. 

hw3.jpg

data AgentD;
infile '/home/Homework 3/AgentD.txt' firstobs=2;
length Customer 8 Date1 8 Date2 8 Address $13;
input Customer Date1 : YYMMDD10. Date2 : YYMMDD10. Address $ &;
run;
proc print data=agentd;
title 'AgentD';
run;

Any ideas on how to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

use scan function

data AgentD;
infile '/home/Homework 3/AgentD.txt' firstobs=2;
length Customer 8 Date1 8 Date2 8 Address $13;
input Customer Date1 : YYMMDD10. Date2 : YYMMDD10. Address $ &;
City=scan(address,1,',');
zipcode=scan(address,-1,',');
run;
proc print data=agentd;
title 'AgentD';
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

use scan function

data AgentD;
infile '/home/Homework 3/AgentD.txt' firstobs=2;
length Customer 8 Date1 8 Date2 8 Address $13;
input Customer Date1 : YYMMDD10. Date2 : YYMMDD10. Address $ &;
City=scan(address,1,',');
zipcode=scan(address,-1,',');
run;
proc print data=agentd;
title 'AgentD';
run;
newbie_grad
Fluorite | Level 6

That worked with some formatting. Now how can I make the ZipCode column a numerical value?

data AgentD;
infile '/home/Homework 3/AgentD.txt' firstobs=2;
length Customer 8 Date1 8 Date2 8 Address $24;
input Customer Date1 : YYMMDD10. Date2 : YYMMDD10. Address $ &;
format Date1 Date2 YYMMDD10.;
City=scan(address,1,',');
ZipCode=scan(address,-1,',');
keep Customer Date1 Date2 City ZipCode;
run;
proc print data=agentd;
title 'AgentD';
run;
novinosrin
Tourmaline | Level 20

use input around the scan like:

ZipCode=input(strip(scan(address,-1,',')),5.);

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3323 views
  • 2 likes
  • 2 in conversation