New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sneh1
Calcite | Level 5

Hi guys

 

i have to solve this question:-

Use proc import to prepare sas dataset from 'grocery coupons' excel files and provide proper variable and value label to all the variables ,provide on the second tab of excel file.

 

i did that :- 

 

proc import datafile='/folders/myfolders/grocery_coupons' out=assign1.grocery_coupons
dbms=xls;
getnames=yes;
run;
data assign1.coupons;
set assign1.grocery_coupons;
label storeid=store_id
hlthfood=health_food_store
size=size_of_store
org=store_oragnization
custid=customer_id
gender=gender
shopfor=who_shopping_for
veg=vegeterain
style=shopping_style
usecoup=use_coupons
week=week
seq=sequence
carry=carryover
coupval=value_of_coupons
amtspent=amount_spent;
run;

 

but i dont know how to create value lables for for all the variable.see the attached file.

 

Someone please help me

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Using the phrase "value labels" makes me think you may have used SPSS at some time. SAS data sets  do not store "value labels" in the data set. Instead SAS uses a Format for how to display any set of values. A default format can be assigned but definition for non-SAS supplied formats has to be made available to SAS session.

 

Proc Format is used to create formats. You can either supply direct statements with values and display value pairs or create formats from data sets with the correct structure and variables. Your examples are simple enough that writing Proc format is likely the way to go.

Example for your ORG variable:

proc format library=work;
value org
1='Emphasizes produce'	
2='Emphasizes deli'	
3='Emphasizes bakery'	
4='No emphasis'
;
run;

Which assumes the ORG variable is numeric. If the value is actually a character value then the part on the left of the = should be in quotes and the name of the format would start with $ to indicate a character valued format.

Then assign the format with a FORMAT statement that lists the variable and then the format to use such as:

Format org org. ;

The period at the end of the second org tells SAS that ORG. is the format to use. You can apply the same format to many variables at a time such as format thisvar thatvar somevar myformatname. ; so that period is important to id the format name.

 

If you use the format statement in a data step then that format becomes the default for the variable and will be used for display when the format is available to the session.

 

One advantage to the SAS FORMAT approach is that you can have multiple similar formats such as

proc format library=work;
value orgshort
1,2,3='Emphasis'	
4='No emphasis'
;
run;

and change analysis or a display simply by changing the assigned format. Groups defined in custom format will be honored in almost any analysis procedure.

In the following code the first proc freq would have 4 categories in the output and the second proc freq would only have two.

proc freq data=assign1.coupons;
   tables org;
   format org org.;
run;
proc freq data=assign1.coupons;
   tables org;
   format org orgshort.;
run;

You do not need to modify a data set to use a different format, just use it in the procedure. You do have to have the format available though which would mean either running the proc format in every session or learning how to store formats in a permanent library and reference the formats in a format search path.

View solution in original post

1 REPLY 1
ballardw
Super User

Using the phrase "value labels" makes me think you may have used SPSS at some time. SAS data sets  do not store "value labels" in the data set. Instead SAS uses a Format for how to display any set of values. A default format can be assigned but definition for non-SAS supplied formats has to be made available to SAS session.

 

Proc Format is used to create formats. You can either supply direct statements with values and display value pairs or create formats from data sets with the correct structure and variables. Your examples are simple enough that writing Proc format is likely the way to go.

Example for your ORG variable:

proc format library=work;
value org
1='Emphasizes produce'	
2='Emphasizes deli'	
3='Emphasizes bakery'	
4='No emphasis'
;
run;

Which assumes the ORG variable is numeric. If the value is actually a character value then the part on the left of the = should be in quotes and the name of the format would start with $ to indicate a character valued format.

Then assign the format with a FORMAT statement that lists the variable and then the format to use such as:

Format org org. ;

The period at the end of the second org tells SAS that ORG. is the format to use. You can apply the same format to many variables at a time such as format thisvar thatvar somevar myformatname. ; so that period is important to id the format name.

 

If you use the format statement in a data step then that format becomes the default for the variable and will be used for display when the format is available to the session.

 

One advantage to the SAS FORMAT approach is that you can have multiple similar formats such as

proc format library=work;
value orgshort
1,2,3='Emphasis'	
4='No emphasis'
;
run;

and change analysis or a display simply by changing the assigned format. Groups defined in custom format will be honored in almost any analysis procedure.

In the following code the first proc freq would have 4 categories in the output and the second proc freq would only have two.

proc freq data=assign1.coupons;
   tables org;
   format org org.;
run;
proc freq data=assign1.coupons;
   tables org;
   format org orgshort.;
run;

You do not need to modify a data set to use a different format, just use it in the procedure. You do have to have the format available though which would mean either running the proc format in every session or learning how to store formats in a permanent library and reference the formats in a format search path.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 12355 views
  • 3 likes
  • 2 in conversation