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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 8878 views
  • 1 like
  • 3 in conversation