i want to transpose the dataset with the condition.
if there is no observation available in dataset only variable is present then no transpose .
and if observation is present then transpose the dataset.
Please help me in this.
Thanks in advance.
Query DICTIONARY.TABLES, then execute code conditionally:
%let count = 0;
proc sql noprint;
select nobs into :count
from dictionary.tables
where libname = "YOURLIB" and memname = "YOURDATASET";
quit;
% if &count. gt 0
%then %do;
/* transpose code */
%end;
I think you would have to do this conditional transpose with a macro, or with a macro %IF statement. In this example, I am looking for the number of observations in SASHELP.CLASS. Naturally you would replace SASHELP and CLASS with the actual libname and data set name. (Note: if the data set is in the WORK library, you have to use libname="WORK" in your SQL WHERE clause).
%macro cond_transp;
proc sql;
select nobs into :nobs from dictionary.tables where libname="SASHELP" and memname="CLASS";
quit;
%if &nobs>0 %then %do;
proc transpose data= ...;
/* Other proc transpose statements go here */
run;
%end;
%mend;
%cond_transp
Note that, with a reasonably recent maintenance level of SAS 9.4, you can use %IF %THEN %DO - %END in open code, so you do not need a macro definition.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.