BookmarkSubscribeRSS Feed
vomer
Obsidian | Level 7

Hi guys,

I have used the following macro to count the number of rows and use it in my dde:

data _NULL_;

if   0 then set TEST nobs=nr;

index=nr+1;

CALL SYMPUT('row2', PUT(index, 5.));

stop;

run;

usage in DDE: FILENAME dataZ13 DDE "excel|[&template.]&section2.!r2c30:r&row2.c36" notab;

I am wondering how I can do the same for the number of columns? I have a dataset where we add a new variable (column) every month. I was wondering if there was some similar macro that can count the number of columns so I do not have to keep changing the column limits in DDE.

Thanks.

2 REPLIES 2
MikeZdeb
Rhodochrosite | Level 12

hi ... one idea (use a separator that's not a character in your data ... I used a TAB) ...

question ...  what's that +1 for (index=nr+1) ... it's added in both examples below

data _null_;

set sashelp.class nobs=obs;

call symputx('obs',obs+1);

call symputx('vars',countc(catx('09'x,of _all_),'09'x)+1);

stop;

run;


or dictionary tables (separated by removes leading spaces in macro vars)...


proc sql noprint;

select nobs+1, nvar into :obs separated by ' ', :vars separated by ' '

from dictionary.tables

where libname eq 'SASHELP' and memname eq 'CLASS';

quit;

Ksharp
Super User

Or compressing code.

%let dsid=%sysfunc(open(sashelp.class));

%let nvar=%sysfunc(attrn(&dsid,nvar));

%let dsid=%sysfunc(close(&dsid));

%put &nvar ;

Ksharp

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 9451 views
  • 1 like
  • 3 in conversation