Class assignment that I am stuck on. Sorry if this is simple. I need to split the last variable in the data City, state, zip code into 2 variables city and zip code. In the code I am calling the variables city and zipcode. I can not figure out how to have sas read the city separate from the zip code. I have tried the input statement that is blocked out with the /*.......*/ (this was done without the format statement and the other input statement shown below) but the city length is not the same distance. I tried a dlm comma statement but not all variables have commas separating,
I tried the copied information statement to no avail.
Data agentd;
informat customer $1. date1 yymmdd10. date2 yymmdd10. city $30. zipcode 6.;
/*input customer $ date1 : yymmdd10. date2 : yymmdd10. city $14. zipcode;*/
input customer date1 date2 city zipcode;
format date1 date2 mmddyy8.;
datalines;
1. 2014-03-11. 2014-05-31. Bremen, KS, 66412
2. 2015-08-06 2015-09-02. Little River, KS, 67457
Id love any suggestions from the masses of experts
Ben
Data agentd;
informat customer $2. date1 yymmdd10. date2 yymmdd10. city $30. zipcode 6. city_zipcode $30.;
input customer $ date1 date2 city_zipcode & $30.;
city = scan(city_zipcode, 1, ',');
zipcode = input(scan(city_zipcode, -1, ' '), 5.);
format date1 date2 mmddyy8.;
datalines;
1. 2014-03-11 2014-05-31 Bremen, KS, 66412
2. 2015-08-06 2015-09-02 Little River, KS, 67457
;
run;
Thank you so very much. so awesome to see the various ways to do this.
If I see that I need to add a variable to this dataset with the same value how would I do that?
example:
For each customer I want there to be a variable named AGENT. Each customer of this data set will have the value for AGENT of D.
I know how to add a computed value but not how to add this added consistent value.
Finding this group is incredible
Thanks again
Data agentd;
informat customer $1. date1 yymmdd10. date2 yymmdd10.;
input customer date1 date2 city_ipcode $30.;
city= substr(city_ipcode,1,length(city_ipcode)-length(scan(city_ipcode,-1,',')));
zipcode=input(scan(city_ipcode,-1,','),6.);
format date1 date2 mmddyy8.;
datalines;
1. 2014-03-11 2014-05-31 Bremen, KS, 66412
2. 2015-08-06 2015-09-02 Little River, KS, 67457
;
run;
Data agentd;
informat customer $2. date1 yymmdd10. date2 yymmdd10. city $30. zipcode 6. city_zipcode $30.;
input customer $ date1 date2 city_zipcode & $30.;
city = prxchange('s/,\s*\d+$//',1,strip(city_zipcode));
zipcode = input(scan(city_zipcode, -1, ' '), 5.);
format date1 date2 mmddyy8.;
datalines;
1. 2014-03-11 2014-05-31 Bremen, KS, 66412
2. 2015-08-06 2015-09-02 Little River, KS, 67457
;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.