- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I want to subset the proc contents results for a specific variable. How can i do that?
Note:
Keep in mind that the dataset have 10000 variables, and so i do not want proc contents of all 10000 variables, instead juist require contents info for specific variable.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can get characteristics of specific variables from dictionary.columns. This example pulls information from one variable in the SASHELP.Class data set.
proc sql;
select *
from dictionary.columns
where libname='SASHELP' and memname='CLASS' and upcase(name) = 'SEX';
quit;
The libname and memname(dataset) must be in all caps. I upcase the variable name for consistency. If you have a list of variable names of interest then use upcase(Name) in ('VARNAME1', 'VARNAME2',....,'VARNAME3') where VARNAMEs are the ones you are interested in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sometimes, when i run dictionary.columns on large dataset, the query hangs.
Is there any alternative way of doing this?
Thanks for this solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
PROC CONTENTS usually performs better for single tables.
Use it to get info on all of the columns for your table without printing but only to store in a SAS dataset.
Then use PROC PRINT or similar with a WHERE statement to display just the variables you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please can you share the code for this, as i tried this, but didnt work as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's some of the code to get you started:
proc contents data=have noprint out=_contents_;
run;
proc print data=_contents_ (obs=10);
run;
This will give you an idea of what the output data set from PROC CONTENTS looks like, and possibly enough information for you to solve your original problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
you didn't say what you want to do with your output
here is code to get you started.
Check the OnLineDoc for the varnum function
getting varnum is the key value you need in order to get format and label
in this program varnum is the loop index i
%let libname = sashelp;
%let memname = class;
DATA _null_;
dsid = open ("&libname..&memname" );
lrecl = attrn(dsid,'lrecl');
n_obs = attrn(dsid,'nobs ');
n_vars = attrn(dsid,'nvars');
do i = 1 to n_vars;
name = varname(dsid,i);
type = vartype(dsid,i);
putlog name= type=;
end;
rc = close (dsid);
stop;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let libname = sashelp;
%let memname = class;
%let name = age;
proc contents data = &libname..&memname
out = out_contents
where = (upcase(name)
eq "%upcase(&name)"));
proc print data = &syslast;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ok thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This code gives following error:
%let libname = sashelp;
%let memname = class;
%let name = age;
proc contents data = &libname..&memname
out = out_contents;
where (upcase(name)
eq "%upcase(&name)"));
22
76
clause.
22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
.
76-322: Syntax error, statement will be ignored.
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@dkanand86
LOL
well, you didn't copy and paste my code above.
what I wrote was a where clause for the output data set
what you typed is a where statement with unmatched parentheses.