- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Is there a way to to print both the variable values AND the value labels in a frequency tabel?
When I use proc freq, at the moment only the value labels are displayed:
Age
up to 16 years: 12 %
17 to 30 years: 14 %
30 to 50 years: 36 %
50 to 65 years: 19 %
65 years and older: 18 %
missing: 18 %
I have defined them for my numeric variable Age with proc format and pplied them in a data step.
How can I cinfigure the system options, so that the output table looks like this:
1: up to 16 years: 12 %
2: 17 to 30 years: 14 %
3: 30 to 50 years: 36 %
4: 50 to 65 years: 19 %
5: 65 years and older: 18 %
9: missing: 1 %
(displaying both values and Labels)
I would appreciate any help.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
While you might need to do a little juggling, here is a way that is less complex and involves little juggling.
For the same of discussion, let's say the variable AGE has a format AGECAT. that translates it into the formatted labels.
Begin by creating a data set holding the percents:
proc freq data=have;
tables age / noprint out=age_counts (keep=age percent)
run;
The table doesn't print, but you can easily use the output data set:
data want;
set age_counts;
category = age;
run;
This creates a second variable with the same value. But when printing, one gets formatted and one doesn't:
proc print data=want;
var category age percent;
format category;
format age agecat.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
He Reeza,
No, I would rather like to check if all values and labels are assigned correctly as stated in the questionnaire and see if the frequencies of each category behave normal at the same time (in other words checking the correctness and plausibility of the data). Age is one of 181 variables that I would like to check.
So I would like to know how to change what is displayed in all the frequency tables by default if that exists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ah, well in that case I don't think there's an easy way to check that. You can check the formats definitions if you wanted fairly easily, but it wouldn't have the counts.
@sylvanaw wrote:
He Reeza,
No, I would rather like to check if all values and labels are assigned correctly as stated in the questionnaire and see if the frequencies of each category behave normal at the same time (in other words checking the correctness and plausibility of the data). Age is one of 181 variables that I would like to check.
So I would like to know how to change what is displayed in all the frequency tables by default if that exists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@sylvanaw wrote:
He Reeza,
No, I would rather like to check if all values and labels are assigned correctly as stated in the questionnaire and see if the frequencies of each category behave normal at the same time (in other words checking the correctness and plausibility of the data). Age is one of 181 variables that I would like to check.
So I would like to know how to change what is displayed in all the frequency tables by default if that exists.
Frequency tables is not the way to check this. PROC CONTENTS will provide the variable name and associated label.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am not looking not for the variable lables, but for the value labels for each category (see example above).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Fancy things can be done with proc template. I have found some papers, but non explaining how to show formatted and unformatted values. Search-string used: "site:sas.com proc template freq".
You could clone the formats and add the value to the text displayed and use those formats in proc freq.
An example using sashelp.class:
proc format;
value $Gender
'M' = 'Male'
'F' = 'Female'
;
run;
proc freq data=sashelp.class;
format Sex $Gender.;
table Sex;
run;
proc format cntlout=work.GenderFmt;
select $Gender;
run;
data work.GenderFmt;
set work.GenderFmt(rename=(label = oldLabel));
length Label $ 10;
drop oldLabel length default;
format Label;
Label = cats(Start, ':', oldLabel);
FmtName = cats(FmtName, '_Clone'); /* will cause trouble with long format names */
run;
proc format cntlin=work.GenderFmt;
run;
proc freq data=sashelp.class;
format Sex $Gender_Clone.;
table Sex;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
While you might need to do a little juggling, here is a way that is less complex and involves little juggling.
For the same of discussion, let's say the variable AGE has a format AGECAT. that translates it into the formatted labels.
Begin by creating a data set holding the percents:
proc freq data=have;
tables age / noprint out=age_counts (keep=age percent)
run;
The table doesn't print, but you can easily use the output data set:
data want;
set age_counts;
category = age;
run;
This creates a second variable with the same value. But when printing, one gets formatted and one doesn't:
proc print data=want;
var category age percent;
format category;
format age agecat.;
run;