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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 6823 views
  • 0 likes
  • 3 in conversation