BookmarkSubscribeRSS Feed
LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

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; 
7 REPLIES 7
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

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

PaigeMiller
Diamond | Level 26

@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 ...
--
Paige Miller
LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

Hi Again,

 

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

 

Thanks,

LMP

PaigeMiller
Diamond | Level 26

Is the value of COUNTYC numeric or character?

 

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

--
Paige Miller
ballardw
Super User

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;
SuzanneDorinski
Lapis Lazuli | Level 10

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.

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 1382 views
  • 0 likes
  • 4 in conversation