In the output i am not able to see the labels . I think there must be a syntax problem
Data _class_s;
set _class_s.Grocery_coupons;
label Storeid =" Store ID "
hlthfood ="Health_food_store"
size = "Size_of_store"
org = "Store_of_organization"
usecoupon = "USE_COUPONS"
week = "Week"
seq = "Sequence"
carry = "Carry_over"
coupval = "Value_of_coupon"
amtspent = "Amount_spent" ;
run;
Nothing wrong with your code, unless your log is showing an error in that you never assigned the libname _class_s
Your code indicates that you are trying to create the file work.class_s, using a file called Grocery_coupons that is located in a libname called _class_s.
The following code worked for me:
libname _class_s "/folders/myfolders"; data _class_s.Grocery_coupons; input Storeid hlthfood size org usecoupon week seq carry coupval amtspent; cards; 1 2 3 4 5 6 7 8 9 10 ; Data _class_s; set _class_s.Grocery_coupons; label Storeid =" Store ID " hlthfood ="Health_food_store" size = "Size_of_store" org = "Store_of_organization" usecoupon = "USE_COUPONS" week = "Week" seq = "Sequence" carry = "Carry_over" coupval = "Value_of_coupon" amtspent = "Amount_spent" ; run;
Art, CEO, AnalystFinder.com
Sir what if after creating labels i want to assign the values :-
I am getting the error :
VALUE Health_food_store
_____
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
104 0='NO'
105 1='YES';
code:
data _class_s.Grocery_coupons;
input Storeid hlthfood size org custid gender shopfor veg style usecoupon week seq carry coupval amtspent;
cards;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
;
Data _class_s;set _class_s.Grocery_coupons;
label Storeid =" Store ID "
hlthfood ="Health_food_store"
size = "Size_of_store"
org = "Store_of_organization"
custid = "Customer_ID"
gender ="Gender"
shopfor = "Who_Shopping_For"
veg ="Vegetarian"
style "SHOPPING_STYLE"
usecoupon = "USE_COUPONS"
week = "Week"
seq = "Sequence"
carry = "Carry_over"
coupval = "Value_of_coupon"
amtspent = "Amount_spent" ;
run;
PROC FORMAT lib=_class_s.Grocery_coupons fmtlib;
proc contents data=_class_s.Grocery_coupons;
run;
VALUE Health_food_store
0='NO'
1='YES';
VALUE Size_of_store
1='SMALL'
2='MEDIUM'
3='LARGE';
VALUE Store_of_organization
1='EMPHASIZES_PRODUCE'
2='EMPHASIZES_DELI'
3='EMPHASIZES_BAKERY'
4=' NO_EMPHASIS' ;
VALUE Gender
0='MALE'
1='FEMALE';
VALUE Who_Shopping_For
1='SELF'
2='SELF_AND_SPOUSE'
3='SELF_AND_FAMILY';
VALUE Vegetarian
0='NO'
1='YES';
VALUE SHOPPING_STYLE
1= 'Biweekly;inbulk'
2= 'Weekly;similar_items'
3= 'often;what_on_sale';
VALUE USE_COUPONS
1='NO'
2='From_newspaper'
3='From_mailing'
4='From_both';
VALUE Carryover
0='Firstperiod'
1='No_coupon'
2='5_percent'
3='15_percent'
4='25_percent';
VALUE Value_of_coupon
1='No_value'
2='5_percent'
3='15_percent'
4='25_percent';
RUN;
options fmtsearch =(_class_s.Grocery_coupons);
data _class_s;
set _class_s.Grocery_coupons;
format hlthfood Health_food_store. size Size_of_store.
org Store_of_organization. gender Gender. shopfor Who_Shopping_For.
veg Vegetarian. style SHOPPING_STYLE. usecoupon USE_COUPONS.
carry Carryover. coupval Value_of_coupon.;
run;
You somehow managed to insert a proc contents into your proc format. Very obvious.
You broke the PROC FORMAT step inserting proc contents:
PROC FORMAT lib=_class_s.Grocery_coupons fmtlib;
proc contents data=_class_s.Grocery_coupons;
run;
VALUE Health_food_store
0='NO'
1='YES';
Move the proc contents at the end of proc format (after RUN; statement);
Is this the correct format to write proper variable and value label to the variables ???? in this no error is coming . But i want to check the format .
PROC FORMAT lib=_class_s.Grocery_coupons fmtlib;
VALUE Health_food_store
0='NO'
1='YES';
VALUE Size_of_store
1='SMALL'
2='MEDIUM'
3='LARGE';
VALUE Store_of_organization
1='EMPHASIZES_PRODUCE'
2='EMPHASIZES_DELI'
3='EMPHASIZES_BAKERY'
4=' NO_EMPHASIS' ;
VALUE Gender
0='MALE'
1='FEMALE';
VALUE Who_Shopping_For
1='SELF'
2='SELF_AND_SPOUSE'
3='SELF_AND_FAMILY';
VALUE Vegetarian
0='NO'
1='YES';
VALUE SHOPPING_STYLE
1= 'Biweekly;inbulk'
2= 'Weekly;similar_items'
3= 'often;what_on_sale';
VALUE USE_COUPONS
1='NO'
2='From_newspaper'
3='From_mailing'
4='From_both';
VALUE Carryover
0='Firstperiod'
1='No_coupon'
2='5_percent'
3='15_percent'
4='25_percent';
VALUE Value_of_coupon
1='No_value'
2='5_percent'
3='15_percent'
4='25_percent';
RUN;
options fmtsearch =(_class_s.Grocery_coupons);
data _class_s;
set _class_s.Grocery_coupons;
format hlthfood Health_food_store. size Size_of_store.
org Store_of_organization. gender Gender. shopfor Who_Shopping_For.
veg Vegetarian. style SHOPPING_STYLE. usecoupon USE_COUPONS.
carry Carryover. coupval Value_of_coupon.;
run;
proc print data=_class_s;
run;
@mehak wrote:
In the output i am not able to see the labels . I think there must be a syntax problem
Data _class_s;
set _class_s.Grocery_coupons;
label Storeid =" Store ID "
hlthfood ="Health_food_store"
size = "Size_of_store"
org = "Store_of_organization"
usecoupon = "USE_COUPONS"
week = "Week"
seq = "Sequence"
carry = "Carry_over"
coupval = "Value_of_coupon"
amtspent = "Amount_spent" ;
run;
Define "output". Procedures like proc print need to be told to use labels, and the viewtables in EG or Base SAS can be configured to either use labels or variable names.
Is this the correct format to write proper variable and value label to the variables ???? in this no error is coming . But i want to check the format .
PROC FORMAT lib=_class_s.Grocery_coupons fmtlib;
VALUE Health_food_store
0='NO'
1='YES';
VALUE Size_of_store
1='SMALL'
2='MEDIUM'
3='LARGE';
VALUE Store_of_organization
1='EMPHASIZES_PRODUCE'
2='EMPHASIZES_DELI'
3='EMPHASIZES_BAKERY'
4=' NO_EMPHASIS' ;
VALUE Gender
0='MALE'
1='FEMALE';
VALUE Who_Shopping_For
1='SELF'
2='SELF_AND_SPOUSE'
3='SELF_AND_FAMILY';
VALUE Vegetarian
0='NO'
1='YES';
VALUE SHOPPING_STYLE
1= 'Biweekly;inbulk'
2= 'Weekly;similar_items'
3= 'often;what_on_sale';
VALUE USE_COUPONS
1='NO'
2='From_newspaper'
3='From_mailing'
4='From_both';
VALUE Carryover
0='Firstperiod'
1='No_coupon'
2='5_percent'
3='15_percent'
4='25_percent';
VALUE Value_of_coupon
1='No_value'
2='5_percent'
3='15_percent'
4='25_percent';
RUN;
options fmtsearch =(_class_s.Grocery_coupons);
data _class_s;
set _class_s.Grocery_coupons;
format hlthfood Health_food_store. size Size_of_store.
org Store_of_organization. gender Gender. shopfor Who_Shopping_For.
veg Vegetarian. style SHOPPING_STYLE. usecoupon USE_COUPONS.
carry Carryover. coupval Value_of_coupon.;
run;
proc print data=_class_s;
run;
To check a format, look at the variables you assigned that format to, if they display as you expected.
You had posted the actual code you ran (including your libname statement and proc import) but, apparently, deleted that post.
If you repost it, I'm sure one of us can show you how to correctly run what you're trying to do.
Art, CEO, AnalystFinder.com
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.