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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.