BookmarkSubscribeRSS Feed
zihdonv19
Obsidian | Level 7

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.

...

 

 

 

...

 

 

 

...

 

 

 

 

 

 

 

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Where is the "VALUE DESCRIPTION" created or stored?

 

This is the output you want, what is the input?

--
Paige Miller
yabwon
Onyx | Level 15

Try:

proc contents NOPRINT
  data=sashelp.class
  out=INFO_DATASET;
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

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.

 

 

zihdonv19
Obsidian | Level 7

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
Tom
Super User Tom
Super User

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.

 

Reeza
Super User

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.

...

 

 

 

...

 

 

 

...

 

 

 

 

 

 

 


 

zihdonv19
Obsidian | Level 7

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;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 529 views
  • 0 likes
  • 6 in conversation