DATA Step, Macro, Functions and more

labels

Reply
Contributor
Posts: 30

labels

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;

Super User
Posts: 8,214

Re: labels

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

 

Contributor
Posts: 30

Re: labels

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;

 

Super User
Posts: 10,534

Re: labels

You somehow managed to insert a proc contents into your proc format. Very obvious.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Trusted Advisor
Posts: 1,848

Re: labels

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);

Contributor
Posts: 30

Re: labels

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;

Super User
Posts: 10,534

Re: labels


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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 30

Re: labels

Posted in reply to KurtBremser

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;

Super User
Posts: 10,534

Re: labels

To check a format, look at the variables you assigned that format to, if they display as you expected.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 8,214

Re: labels

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

 

Ask a Question
Discussion stats
  • 9 replies
  • 207 views
  • 0 likes
  • 4 in conversation