Write and run SAS programs in your web browser

Blank variable, not defined

Reply
Occasional Contributor LMP
Occasional Contributor
Posts: 14

Blank variable, not defined

Hello SAS community,

 

    I am defining  a variable  by creating a few new varible such as  county. However, nothing is in the column for county (basically blanks). I tried it without quotations (double and single) and it didn't work either.  Also, when I ran the code, I didn't get any errors.  I am not sure why it isn't working, are there any suggestions on how to fix this problem?

 

Thanks,

LMP

libname mydata "/folders/myshortcuts/myfolder";
run;

Data mydata.ideaths08;
set mydata.deaths08; 
/* create and define variables in death 2008 dataset*/
/*City and county definitions*/
if countyc='61' then county='hamilton'; run; 
Trusted Advisor
Posts: 1,670

Re: Blank variable, not defined


LMP wrote:

Hello SAS community,

 

    I am defining  a variable  by creating a few new varible such as  county. However, nothing is in the column for county (basically blanks). I tried it without quotations (double and single) and it didn't work either.  Also, when I ran the code, I didn't get any errors.  I am not sure why it isn't working, are there any suggestions on how to fix this problem?

 

Thanks,

LMP

libname mydata "/folders/myshortcuts/myfolder";
run;

Data mydata.ideaths08;
set mydata.deaths08; 
/* create and define variables in death 2008 dataset*/
/*City and county definitions*/
if countyc='61' then county='hamilton'; run; 

You will get much quicker and better answers if you show us your input data, for example the first 10 rows of mydata.deaths08 (and you will get fewer complaints from people like me).

 

I assume the variable that is entirely missing is COUNTY ... but you haven't explicitly said that, so am I right?

 

This can happen if COUNTYC in mydata.deaths08 is not present, or doesn't contain the value 61, or for a number of other reasons which we can quickly figure out if we could only see part of your input data.

Occasional Contributor LMP
Occasional Contributor
Posts: 14

Re: Blank variable, not defined

Hi,

 

  Countyc consists of numerical values. And I am trying to creating a new variable, county, based on one numerical value in the code I submited in a previous post.  Thus, 61 (numerical vaule for countyc) represents hamilton county.

 

-LMP

Trusted Advisor
Posts: 1,670

Re: Blank variable, not defined

[ Edited ]

LMP wrote:

Hi,

 

  Countyc consists of numerical values. And I am trying to creating a new variable, county, based on one numerical value in the code I submited in a previous post.  Thus, 61 (numerical vaule for countyc) represents hamilton county.

 

-LMP


Then your code has failed because you put 61 in quotes ... if it is a numeric then you want to use

 

if countyc=61 then ...
Occasional Contributor LMP
Occasional Contributor
Posts: 14

Re: Blank variable, not defined

Hi Again,

 

  I cannot share the input data because it is confidential. The value does exist in the data set too.

 

Thanks,

LMP

Trusted Advisor
Posts: 1,670

Re: Blank variable, not defined

Is the value of COUNTYC numeric or character?

 

You can share with us the values of the variable COUNTYC without violating any confidentiality.

Super User
Posts: 10,857

Re: Blank variable, not defined

Show the log with teh code and data.

If your countyc value has leading spaces, ie ' 61' then the comparison fails. 

If you already have a variable named County that is numeric then the result would be missing because a numeric variable cannot have the value 'hamilton'.

 

Note that a common approach to this issue is instead of a bunch of IF/Then statements to use a custom format to display the desired text.

proc format library=work;
value $myCountyC
'61' = 'Hamiliton'
'63' = 'Harvard'
other = 'Unknown code'
;
run;

data junk;
   input countyc $;
datalines;
63
61
63
22
;
run;

proc print data=junk;
   var countyc;
   format countyc $myCountyC.;
run;
Contributor
Posts: 70

Re: Blank variable, not defined

One other possibility is that the county code is a county FIPS code, and may have a leading zero.  The FIPS code for Hamilton County, Ohio is 061.  https://www2.census.gov/geo/docs/reference/codes/files/st39_oh_cou.txt has the list for Ohio, while https://www.census.gov/geo/reference/codes/cou.html lets you choose other states, territories, or all of the United States.

Ask a Question
Discussion stats
  • 7 replies
  • 154 views
  • 0 likes
  • 4 in conversation