Write and run SAS programs in your web browser

How to make value labels become the value

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

How to make value labels become the value

please help me with this....

i want to put value in variable but its showing error....

reply fast please......

 

code;-

 


proc format lib=Preeti;
value hlthfood
0='No'
1='Yes';
value size
1='Small'
2='Medium'
3='Large';
value org
1='Emphasizes produce'
2='Emphasizes deli'
3='Emphasizes bakery'
4='No emphasis';
value gender
0='Male'
1='Female';
value shopfor
1='Self'
2='Self and spouse'
3='Self and family';
value veg
0='No'
1='Yes';
value style
1='Biweekly' and 'in bulk'
2='Weekly' and 'similar items'
3='Often' and 'whats on sale';
value usecoup
1='No'
2='From newspaper'
3='From mailings'
4='From both';

value carry
0='First period'
1='No coupon'
2='5 percent'
3='15 percent'
4='25 percent';

Value coupval
1='No value'
2='5 percent'
3='15 percent'
4='25 percent'
run;

data preeti.grocery_coupons1;
set Preeti.grocery_coupons;
format preeti.hlthfood hlthfood.;
format size size. ;
format org org. ;
format custid custid. ;
format gender gender. ;
format shopfor shopfor. ;
format veg veg. ;
format style style. ;
format usecoup usecoup. ;
format week week. ;
format seq seq. ;
format carry carry. ;
format coupval coupval. ;
format amtspent amtspent. ;
run;

 

error ;-

 

data preeti.grocery_coupons1;
 
111 set Preeti.grocery_coupons;
112 format preeti.hlthfood hlthfood.;
_________
484
ERROR: Invalid variable specification, preeti.hlthfood. Variable names of the form X.X must be either FIRST.X or LAST.X.
ERROR: The name preeti.hlthfood is not a valid SAS name.
NOTE 484-185: Format HLTHFOOD was not found or could not be loaded.
 
113 format size size. ;
_____
484
NOTE 484-185: Format SIZE was not found or could not be loaded.
 
114 formatorgorg. ;
____
484
NOTE 484-185: Format ORG was not found or could not be loaded.
 
115 formatcustidcustid. ;
_______
484
NOTE 484-185: Format CUSTID was not found or could not be loaded.
 
116 formatgendergender. ;
_______
484
NOTE 484-185: Format GENDER was not found or could not be loaded.
 
117 formatshopforshopfor. ;
________
484
NOTE 484-185: Format SHOPFOR was not found or could not be loaded.
 
118 formatvegveg. ;
____
484
NOTE 484-185: Format VEG was not found or could not be loaded.
 
119 formatstylestyle. ;
______
484
NOTE 484-185: Format STYLE was not found or could not be loaded.
 
120 formatusecoupusecoup. ;
________
484
NOTE 484-185: Format USECOUP was not found or could not be loaded.
 
121 formatweekweek. ;
_____
484
NOTE 484-185: Format WEEK was not found or could not be loaded.
 
122 formatseqseq. ;
____
484
NOTE 484-185: Format SEQ was not found or could not be loaded.
 
123 formatcarrycarry. ;
______
484
NOTE 484-185: Format CARRY was not found or could not be loaded.
 
124 formatcoupvalcoupval. ;
________
484
NOTE 484-185: Format COUPVAL was not found or could not be loaded.
 
125 formatamtspentamtspent. ;
_________
484
NOTE 484-185: Format AMTSPENT was not found or could not be loaded.
 
126 run;

Accepted Solutions
Solution
‎06-28-2017 02:58 PM
PROC Star
Posts: 7,477

Re: How to make value labels become the value

You have a couple of problems with your code. I presume you used a libname statement to specify the Preeti library, but you never used the fmtsearch option to tell SAS that is where your formats exist.

 

Plus, you included that libname in one of your assignment statements, which you should not have done. i.e., you used:

format preeti.hlthfood hlthfood.;

when you should have used:

format hlthfood hlthfood.;

You also specified some formats that you never created, like custid.

 

I didn't correct all of those errors, but the following should be enough for you to correct (i.e., delete the unassigned format declarations):

libname Preeti '/folders/myfolders';
proc format lib=Preeti;
value hlthfood
0='No'
1='Yes';
value size
1='Small'
2='Medium'
3='Large';
value org
1='Emphasizes produce'
2='Emphasizes deli'
3='Emphasizes bakery'
4='No emphasis';
value gender
0='Male'
1='Female';
value shopfor
1='Self'
2='Self and spouse'
3='Self and family';
value veg
0='No'
1='Yes';
value style
1='Biweekly' and 'in bulk'
2='Weekly' and 'similar items'
3='Often' and 'whats on sale';
value usecoup
1='No'
2='From newspaper'
3='From mailings'
4='From both';
value carry
0='First period'
1='No coupon'
2='5 percent'
3='15 percent'
4='25 percent';
Value coupval
1='No value'
2='5 percent'
3='15 percent'
4='25 percent'
run;

data Preeti.grocery_coupons;
  input hlthfood size org custid gender shopfor veg
    style usecoup week seq carry coupval amtspent;
  cards;
0 1 2 3 1 1 1 1 1 1 1 1 1 1
1 2 3 2 0 1 1 1 1 1 1 1 1 1
;

options fmtsearch=(preeti);
data preeti.grocery_coupons1;
set Preeti.grocery_coupons;
format preeti.hlthfood hlthfood.;
format hlthfood hlthfood.;
format size size. ;
format org org. ;
format custid custid. ;
format gender gender. ;
format shopfor shopfor. ;
format veg veg. ;
format style style. ;
format usecoup usecoup. ;
format week week. ;
format seq seq. ;
format carry carry. ;
format coupval coupval. ;
format amtspent amtspent. ;
run;
 

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎06-28-2017 02:58 PM
PROC Star
Posts: 7,477

Re: How to make value labels become the value

You have a couple of problems with your code. I presume you used a libname statement to specify the Preeti library, but you never used the fmtsearch option to tell SAS that is where your formats exist.

 

Plus, you included that libname in one of your assignment statements, which you should not have done. i.e., you used:

format preeti.hlthfood hlthfood.;

when you should have used:

format hlthfood hlthfood.;

You also specified some formats that you never created, like custid.

 

I didn't correct all of those errors, but the following should be enough for you to correct (i.e., delete the unassigned format declarations):

libname Preeti '/folders/myfolders';
proc format lib=Preeti;
value hlthfood
0='No'
1='Yes';
value size
1='Small'
2='Medium'
3='Large';
value org
1='Emphasizes produce'
2='Emphasizes deli'
3='Emphasizes bakery'
4='No emphasis';
value gender
0='Male'
1='Female';
value shopfor
1='Self'
2='Self and spouse'
3='Self and family';
value veg
0='No'
1='Yes';
value style
1='Biweekly' and 'in bulk'
2='Weekly' and 'similar items'
3='Often' and 'whats on sale';
value usecoup
1='No'
2='From newspaper'
3='From mailings'
4='From both';
value carry
0='First period'
1='No coupon'
2='5 percent'
3='15 percent'
4='25 percent';
Value coupval
1='No value'
2='5 percent'
3='15 percent'
4='25 percent'
run;

data Preeti.grocery_coupons;
  input hlthfood size org custid gender shopfor veg
    style usecoup week seq carry coupval amtspent;
  cards;
0 1 2 3 1 1 1 1 1 1 1 1 1 1
1 2 3 2 0 1 1 1 1 1 1 1 1 1
;

options fmtsearch=(preeti);
data preeti.grocery_coupons1;
set Preeti.grocery_coupons;
format preeti.hlthfood hlthfood.;
format hlthfood hlthfood.;
format size size. ;
format org org. ;
format custid custid. ;
format gender gender. ;
format shopfor shopfor. ;
format veg veg. ;
format style style. ;
format usecoup usecoup. ;
format week week. ;
format seq seq. ;
format carry carry. ;
format coupval coupval. ;
format amtspent amtspent. ;
run;
 

Art, CEO, AnalystFinder.com

 

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 167 views
  • 1 like
  • 2 in conversation