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
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.
Sometimes, when i run dictionary.columns on large dataset, the query hangs.
Is there any alternative way of doing this?
Thanks for this solution.
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.
Please can you share the code for this, as i tried this, but didnt work as expected.
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.
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;
%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;
Ok thanks
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;
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: