Help using Base SAS procedures

Comparing numerical variable w/ char constants

Reply
Occasional Contributor
Posts: 7

Comparing numerical variable w/ char constants

[ Edited ]

I am trying to change the numerical variable to read as either 1, 10,20 or 100 but I am getting the errors as shown below.

Kindly help.

 

data HARVEST_UTILIZE_BEANS_enid2;
set HARVEST_UTILIZE_BEANS_enid1;
if HUB_UNITFRESHHV="Kg" then HUB_UNITFRESHHV=1;
if HUB_UNITFRESHHV="Basin (20 pounds)" then HUB_UNITFRESHHV=10;
if HUB_UNITFRESHHV= "Tin/Bucket (20kg)" then HUB_UNITFRESHHV=20;
if HUB_UNITFRESHHV ="Bag/sac 100 kg" then HUB_UNITFRESHHV=100;
/*standardizing the prices, quantities and units of output beans harvested*/
if HUB_UNITGREENC="Kg" then HUB_UNITGREENC=1;
if HUB_UNITGREENC="Tin/Bucket (20Kg)" then HUB_UNITGREENC=20;
if HUB_UNITGREENC ="Basin (20 pounds)" then HUB_UNITGREENC=10;
if HUB_UNITGREENC="Bag/sac 100 kg" then HUB_UNITGREENC=100;
run;

 

 

OTE: Character values have been converted to numeric values at the places given by: (Line)Smiley SadColumn).
      25:20   26:20   27:21   28:21   30:19   31:19   32:20   33:19   
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=101 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-01-B-2 HUB_BVNAME=KILEGEYA
name2=kilegeya(Bush) code=369 I_L=Local HUB_PLOTNO=2 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=0 HUB_UNITFRESHHV=Kg HUB_DRYHV=50
HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=0 HUB_UNITFRESHC=. HUB_DRYC=20 HUB_UNITDRYC=Kg HUB_QTYFORSEED=5 comment=
BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=1
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
2                                                          The SAS System                          08:57 Tuesday, September 12, 2017

NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=103 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-03-B-1 HUB_BVNAME=Kanyebwa
name2=kanyebwa(Bush) code=262 I_L=Local HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=5 HUB_UNITFRESHHV=Kg HUB_DRYHV=20
HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=5 HUB_UNITFRESHC=Kg HUB_DRYC=15 HUB_UNITDRYC=Bag/sac 50 kg
HUB_QTYFORSEED=1 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=2
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=104 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-04-B-1 HUB_BVNAME=kanyebwa
name2=kanyebwa(Bush) code=262 I_L=Local HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=10 HUB_UNITFRESHHV=Kg HUB_DRYHV=20
HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=10 HUB_UNITFRESHC=Kg HUB_DRYC=15 HUB_UNITDRYC=Kg HUB_QTYFORSEED=5
comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=3
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=106 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-06-B-1 HUB_BVNAME=obweru
name2=obweru(Bush) code=80 I_L=Selected HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=2 HUB_UNITFRESHHV=Kg HUB_DRYHV=5
HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=2 HUB_UNITFRESHC=Kg HUB_DRYC=2 HUB_UNITDRYC=Kg HUB_QTYFORSEED=3 comment=
BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=4
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=107 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-07-B-1
HUB_BVNAME=Kaki Round Small name2=kaki round small(Bush) code=202 I_L=Local HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=.
HUB_FRESHHV=0.5 HUB_UNITFRESHHV=Basin (20 pounds) HUB_DRYHV=9 HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=0.5
HUB_UNITFRESHC=Basin (20 pounds) HUB_DRYC=5 HUB_UNITDRYC=Kg HUB_QTYFORSEED=4 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=5
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=108 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-08-B-1 HUB_BVNAME=Kanyebwa
name2=kanyebwa(Bush) code=262 I_L=Local HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=2 HUB_UNITFRESHHV=Tin/Bucket (20kg)
HUB_DRYHV=1 HUB_UNITDRYHV=Bag/sac 100 kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=1 HUB_UNITFRESHC=Tin/Bucket (20kg) HUB_DRYC=3
HUB_UNITDRYC=Tin/Bucket (20kg) HUB_QTYFORSEED=20 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=6
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
3                                                          The SAS System                          08:57 Tuesday, September 12, 2017

NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=109 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-09-B-1 HUB_BVNAME=obweru
name2=obweru(Bush) code=80 I_L=Selected HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=0 HUB_UNITFRESHHV=Kg HUB_DRYHV=1
HUB_UNITDRYHV=Basin (20 pounds) HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=0 HUB_UNITFRESHC=. HUB_DRYC=5 HUB_UNITDRYC=Kg
HUB_QTYFORSEED=7 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=7
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=110 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-10-B-1 HUB_BVNAME=obweru
name2=obweru(Bush) code=80 I_L=Selected HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=2 HUB_UNITFRESHHV=Tin/Bucket (20kg)
HUB_DRYHV=3 HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=2 HUB_UNITFRESHC=Kg HUB_DRYC=3 HUB_UNITDRYC=Kg
HUB_QTYFORSEED=0 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=8
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=111 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-11-B-2 HUB_BVNAME=obwirugavu
name2=obwirugavu(Bush) code=43 I_L=Improved HUB_PLOTNO=2 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=5 HUB_UNITFRESHHV=Kg
HUB_DRYHV=2 HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=5 HUB_UNITFRESHC=Kg HUB_DRYC=2 HUB_UNITDRYC=Kg
HUB_QTYFORSEED=0 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=9
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=112 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-12-B-2 HUB_BVNAME=Bumyufu
name2=bumyufu(Bush) code=526 I_L=Improved HUB_PLOTNO=2 HUB_GREENHV=0 HUB_UNITGREENHV=. HUB_FRESHHV=0 HUB_UNITFRESHHV=Kg HUB_DRYHV=1
HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=0 HUB_UNITFRESHC=. HUB_DRYC=0 HUB_UNITDRYC=. HUB_QTYFORSEED=1 comment=
BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=10
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=114 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-14-B-2
HUB_BVNAME=Kaki Round Small name2=kaki round small(Bush) code=202 I_L=Local HUB_PLOTNO=2 HUB_GREENHV=0 HUB_UNITGREENHV=.
HUB_FRESHHV=0 HUB_UNITFRESHHV=Kg HUB_DRYHV=3 HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=0 HUB_UNITFRESHC=.
HUB_DRYC=3 HUB_UNITDRYC=Kg HUB_QTYFORSEED=0 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=11
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
4                                                          The SAS System                          08:57 Tuesday, September 12, 2017

NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.
NOTE: Invalid numeric data, 'Tin/Bucket (20Kg)' , at line 31 column 19.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 32 column 20.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 33 column 19.
HH_ID=118 region=Eastern region dist=KAMULI scounty=KISOZI parish=MAGOGO village=BUKWALU plot_id=001-18-B-1
HUB_BVNAME=White Haricot/white name2=white haricot/white(Bush) code=1 I_L=Local HUB_PLOTNO=1 HUB_GREENHV=0 HUB_UNITGREENHV=.
HUB_FRESHHV=6 HUB_UNITFRESHHV=Kg HUB_DRYHV=5 HUB_UNITDRYHV=Kg HUB_GREENC=0 HUB_UNITGREENC=Kg HUB_FRESHC=6
HUB_UNITFRESHC=Tin/Bucket (20kg) HUB_DRYC=4 HUB_UNITDRYC=Kg HUB_QTYFORSEED=1 comment=  BEAN_MERGE_COMMENT=  _ERROR_=1 _N_=12
NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.
NOTE: Invalid numeric data, 'Basin (20 pounds)' , at line 26 column 20.
NOTE: Invalid numeric data, 'Tin/Bucket (20kg)' , at line 27 column 21.
NOTE: Invalid numeric data, 'Bag/sac 100 kg' , at line 28 column 21.
NOTE: Over 100 NOTES, additional NOTES suppressed.
NOTE: Invalid numeric data, 'Kg' , at line 30 column 19.

Super Contributor
Posts: 330

Re: SAS Coding

It looks like the variables HUB_UNITFRESHHV and HUB_UNITGREENC are defined as numeric but you're trying to comapre them with character values.

Occasional Contributor
Posts: 7

Re: SAS Coding

ChrisBrooks:

Could you please advise on an alternative way of coding this?

 

Super User
Super User
Posts: 6,718

Re: SAS Coding

This statement doesn't make much sense.

 

if HUB_UNITFRESHHV="Kg" then HUB_UNITFRESHHV=1;

A varaible cannot be both numeric and character at the same time.

 

Your error message

 

NOTE: Invalid numeric data, 'Kg' , at line 25 column 20.

seems to indicate that HUB_UNITFRESHHV is already a number.

If it is printing as Kg then you probably have a format attached to it.

See what values are actually in the data.  For example run a PROC FREQ and remove the format.

proc freq data=HARVEST_UTILIZE_BEANS_enid1;
  tables HUB_UNITFRESHHV ;
  format _all_ ;
run;

 

Contributor
Posts: 68

Re: SAS Coding

[ Edited ]

Try using proc format. In this approach, you have retained your original variable as numeric and masked the values by creating a user-defined format.  Notice that i forced the values to uppercase - this is to standardize my data. "A" is not the same as "a".

proc format;
  value $hubfmt
  'KG'=1
 'BASIN (20 POUNDS)=2
 other='Other'
;
run;

options fmtsearch=(WORK);

/* Here's my sample data */
data WANT;
  input hub $30.;
  cards;
kg
basin (20 pounds)
test
;
run;

proc sql;
  update WANT
  set hub=upcase(hub);
quit;

proc datasets lib=WORK; *Change work to library where your data is;
  modify WANT;
  format HUB $HUBFMT.
run;
quit;

  
Ask a Question
Discussion stats
  • 4 replies
  • 120 views
  • 3 likes
  • 4 in conversation