- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.