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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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