BookmarkSubscribeRSS Feed
VD
Calcite | Level 5 VD
Calcite | Level 5
Is there a way to count the number of variables in a dataset?
Thanks.
6 REPLIES 6
Peter_C
Rhodochrosite | Level 12
why?
VD
Calcite | Level 5 VD
Calcite | Level 5
The output dataset of my code should have a defined number of variables (after various merge operations). I want to build an error check which displays the number of variables in the output data. Thanks.
Peter_C
Rhodochrosite | Level 12
after the step where table lib.your_table is wriitten, you can put the number of columns into a macro variable (&n_columns) with the syntax[pre]%let n_columns = none ;
proc sql noprint ;
select nVar
into :n_columns separated by ' '
from dictionary.tables
where libname= 'LIB'
& memname= 'YOUR_TABLE'
;
quit ;
%put your_table has &n_columns columns ;[/pre]If the table does not exist, the macro variable n_columns will hold "none".
VD
Calcite | Level 5 VD
Calcite | Level 5
Many Thanks, Peter.
P_J
Calcite | Level 5 P_J
Calcite | Level 5
3078 data a;
3079 a = 10;
3080 label a = "number";
3081 b = vlabel(a);
3082
3083 run;

NOTE: The data set WORK.A has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds


3084
3085 data _null_;
3086 set sashelp.vtable;
3087 where libname ="WORK" AND memname = upcase("a");
3088 put "nu of var=" nvar;
3089 run;

nu of var=2
VD
Calcite | Level 5 VD
Calcite | Level 5
Excellent solution! Thanks P.J.

V

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 6141 views
  • 0 likes
  • 3 in conversation