BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kolobok
Calcite | Level 5

Hi!

I am new to SAS, to please forgive if this is a rather elementary question.

I have a data set that has lets say 15 observations. I am able to count them using _N_ as well as proc sql count function.

I want to declare an array of the size N where N would be equal to the number of observations...

proc sql;

select count (col1) ;

from dataset1;

quit;

array (N) $;

Thank you in advance for all you help!

1 ACCEPTED SOLUTION

Accepted Solutions
CTorres
Quartz | Level 8

To do this you have to create a macro variable and the use it in the data step:

proc sql noprint;
   select Count(*) into :dim
   from sashelp.class;
quit;

%put &dim;

data _null_;
   /* statements.... */

   array my_array(&dim) $;
   /* more statements  ....  */ 

run;

Regards,

View solution in original post

4 REPLIES 4
CTorres
Quartz | Level 8

To do this you have to create a macro variable and the use it in the data step:

proc sql noprint;
   select Count(*) into :dim
   from sashelp.class;
quit;

%put &dim;

data _null_;
   /* statements.... */

   array my_array(&dim) $;
   /* more statements  ....  */ 

run;

Regards,

Kolobok
Calcite | Level 5

Thank you so much for the quick reply! This did the trick!

Haikuo
Onyx | Level 15

Obviously count(*) will be the most accurate approach, but it could take some time if doing it on a huge table. Then you could try to get the number of obs from Meta data instead of actually counting it on the fly:

1)

data _null_;

  call symputx('nobs', nobs);

stop;

set sashelp.class nobs=nobs;

run;

%put &nobs;

2)

proc sql;

  select nobs into :nobs from dictionary.tables where libname='SASHELP' AND MEMNAME='CLASS';QUIT;

%put &nobs;

Haikuo

Kolobok
Calcite | Level 5

Thank you so much for your reply Haikuo! I am just learning SAS and I am very happy I found this board!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1478 views
  • 3 likes
  • 3 in conversation