I expect to get this kind of table (as a separate SAS dataset rather than just display in the "results viewer"):
VARIABLE NAME |
DESCRIPTION/LABEL |
TYPE/ FORMAT |
VALUE DESCRIPTION |
SEX |
Sex of study participant |
Char |
1 = Male 2 = Female |
DATE |
Date of diagnosis |
Num |
YYMMDD10. |
... |
|
|
|
... |
|
|
|
... |
|
|
|
|
|
|
|
Where is the "VALUE DESCRIPTION" created or stored?
This is the output you want, what is the input?
Try:
proc contents NOPRINT
data=sashelp.class
out=INFO_DATASET;
run;
I'm afraid that your Value Description will have to come from somewhere else unless you have created such a data set somewhere. IF you have a custom format you could extract the information to some extent from the format information but will be up to you to format it, especially with large numbers of values.
Type and Format would be separate columns in the output of Proc Contents, along with the variable name, label and order in the data set.
Proc contents can create data sets, or you can extract information from SASHELP.VCOLUMN or Dictionary.Columns in Proc SQL after filtering for the library and member name for the desired data set.
Thanks for your suggestion. I was just surprised SAS does not have this kind of coding...
But do you think making the following table is feasible in SAS? That is: I want to display values for all the character variables with their labels of values?
CHAR_VAR_NAME | OPTION_VALUE | LABEL |
SEX | 1 | Male |
SEX | 2 | Female |
DRUG | 1 | A |
DRUG | 2 | B |
DRUG | 3 | C |
If you want to see the definition of formats use PROC FORMAT.
So if you have these two user defined formats:
proc format;
value sex 1='Male' 2='Female';
value drug 1='A' 2='B' 3='C';
run;
And run PROC FORMAT with FMTLIB option you get a print out like this:
---------------------------------------------------------------------------- | FORMAT NAME: DRUG LENGTH: 1 NUMBER OF VALUES: 3 | | MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH: 1 FUZZ: STD | |--------------------------------------------------------------------------| |START |END |LABEL (VER. V7|V8 01MAR2024:10:53:45)| |----------------+----------------+----------------------------------------| | 1| 1|A | | 2| 2|B | | 3| 3|C | ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- | FORMAT NAME: SEX LENGTH: 6 NUMBER OF VALUES: 2 | | MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH: 6 FUZZ: STD | |--------------------------------------------------------------------------| |START |END |LABEL (VER. V7|V8 01MAR2024:10:53:45)| |----------------+----------------+----------------------------------------| | 1| 1|Male | | 2| 2|Female | ----------------------------------------------------------------------------
So run PROC CONTENTS to see the information on the VARIABLES. And run PROC FORMAT to see the information on any formats that are being used with those variables.
Note that format definitions are INDEPENDENT of the variables they are used with. So if you have 20 variables that all use the same codelist you only need to define and use one format.
You can get this information, it's just not in one place.
There are assumptions of course, that you have labels specified, which are the descriptions and SAS formats are being used.
proc sql;
create table part1 as
select name, label, type, format
from sashelp.vcolumn
where libname='SASHELP' and memname='CARS';
quit;
The second part depends on where you store the formats, assuming you know the formats, you can then do something like the following.
proc format cntlout = format_data;
select sex_fmt ...;
run;
That should get you started at least.
@zihdonv19 wrote:
I expect to get this kind of table (as a separate SAS dataset rather than just display in the "results viewer"):
VARIABLE NAME
DESCRIPTION/LABEL
TYPE/ FORMAT
VALUE DESCRIPTION
SEX
Sex of study participant
Char
1 = Male
2 = Female
DATE
Date of diagnosis
Num
YYMMDD10.
...
...
...
Thank you everyone @Reeza @Tom @ballardw @yabwon @PaigeMiller , I generated the following to achieve my goal.
data exdata;
input sex drug $;
datalines;
0 A
1 B
1 C
0 A
1 B
0 C
;
run;
proc contents data=exdata; run;
proc format;
value sex 0='Male' 1='Female';
run;
proc format;
value $drug 'A'='Drug A' 'B'='Drug B' 'C'='Drug C';
run;
data exdata_label; set exdata;
format sex sex. drug $drug.;
label sex = 'gender' drug = 'Type of Medication';
run;
proc sql;
create table part1 as
select name, label as label_var, type, format
from sashelp.vcolumn
where libname='WORK' and memname='EXDATA_LABEL';
quit;
proc format cntlout = format_data (keep=fmtname start label);
select sex $drug;
run;
data value; set format_data; name = lowcase(fmtname); drop fmtname; run;
proc sql;
create table var_info as
select a.name, b.label_var, a.start, a.label, b.type, b.format
from value as a
left join part1 as b
on a.name = b.name
order by name, start
;
quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.