Tried to change numeric to character to match a map data set, and help.

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Tried to change numeric to character to match a map data set, and help.

Hi! I'm trying to create a map using ZCTAs and then number of doctors in a zip code, but I'm having issues with import. This is my code for SAS 9.4:

 

/*Import ZCTA boundary file*/
Proc MAPIMPORT OUT=sczip
			Datafile= "C:\tl_2010_45_zcta510\tl_2010_45_zcta510.shp";
run;
/* import excel file*/
PROC IMPORT OUT= WORK.zipsum
			DATAFILE="C:\allzipsum.xlsx"
            DBMS=xlsx replace;
			GETNAMES=YES;
RUN;
/*change zipcode to character*/
data work.zipsum;
ZCTA5CE10= put(zipcode,5.);
run;

The ZCTA variable in the map data set is character and has the format and informat $5, and I have to match it.

 

SAS keeps telling me that zipcode is uninitialized. Then it deletes the other variable in the dataset. 

 

I tried using DBDSOPTS, and SAS didn't recognize the command, so I'm at a loss of what to do next.


Accepted Solutions
Solution
‎02-21-2018 02:07 PM
Super User
Posts: 23,700

Re: Tried to change numeric to character to match a map data set, and help.

Posted in reply to jesspurse

You don't have a SET statement and you shouldn't use the same data set name again, that will likely destroy your original data so you'll have to re-import it again. 

 

data work.zipsum_with_zipCode;
set zipsum;

ZCTA5CE10= put(zipcode,5.);

run;

jesspurse wrote:

Hi! I'm trying to create a map using ZCTAs and then number of doctors in a zip code, but I'm having issues with import. This is my code for SAS 9.4:

 

/*Import ZCTA boundary file*/
Proc MAPIMPORT OUT=sczip
			Datafile= "C:\tl_2010_45_zcta510\tl_2010_45_zcta510.shp";
run;
/* import excel file*/
PROC IMPORT OUT= WORK.zipsum
			DATAFILE="C:\allzipsum.xlsx"
            DBMS=xlsx replace;
			GETNAMES=YES;
RUN;
/*change zipcode to character*/
data work.zipsum;
ZCTA5CE10= put(zipcode,5.);
run;

The ZCTA variable in the map data set is character and has the format and informat $5, and I have to match it.

 

SAS keeps telling me that zipcode is uninitialized. Then it deletes the other variable in the dataset. 

 

I tried using DBDSOPTS, and SAS didn't recognize the command, so I'm at a loss of what to do next.


 

View solution in original post


All Replies
Solution
‎02-21-2018 02:07 PM
Super User
Posts: 23,700

Re: Tried to change numeric to character to match a map data set, and help.

Posted in reply to jesspurse

You don't have a SET statement and you shouldn't use the same data set name again, that will likely destroy your original data so you'll have to re-import it again. 

 

data work.zipsum_with_zipCode;
set zipsum;

ZCTA5CE10= put(zipcode,5.);

run;

jesspurse wrote:

Hi! I'm trying to create a map using ZCTAs and then number of doctors in a zip code, but I'm having issues with import. This is my code for SAS 9.4:

 

/*Import ZCTA boundary file*/
Proc MAPIMPORT OUT=sczip
			Datafile= "C:\tl_2010_45_zcta510\tl_2010_45_zcta510.shp";
run;
/* import excel file*/
PROC IMPORT OUT= WORK.zipsum
			DATAFILE="C:\allzipsum.xlsx"
            DBMS=xlsx replace;
			GETNAMES=YES;
RUN;
/*change zipcode to character*/
data work.zipsum;
ZCTA5CE10= put(zipcode,5.);
run;

The ZCTA variable in the map data set is character and has the format and informat $5, and I have to match it.

 

SAS keeps telling me that zipcode is uninitialized. Then it deletes the other variable in the dataset. 

 

I tried using DBDSOPTS, and SAS didn't recognize the command, so I'm at a loss of what to do next.


 

New Contributor
Posts: 4

Re: Tried to change numeric to character to match a map data set, and help.

THANK YOU. That worked perfectly. I knew it was something simple I was missing; you spend so long staring at the code that it all blurs together.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 90 views
  • 0 likes
  • 2 in conversation