BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

I have this:

proc sql;
select counts (*) into: avariableName from mytable;
quit;

Respectfully,

blue & blue

Blue Blue
4 REPLIES 4
mkeintz
PROC Star

Search on the web for URL that contain the three words "sas sql into".

 

The first link the appeared for my search was

 

SAS(R) 9.3 SQL Procedure User's Guide 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

Actually I suspect it does nothing except throw an error because there is no function COUNTS.

Using a data set I know exists:

109  proc sql;
110  select counts (*) into: avariableName
111  from sashelp.class;
ERROR: * used for a function other than COUNT.
ERROR: Function COUNTS could not be located.
112  quit;

Using the function Count, that does exist:

113  proc sql;
114  select count (*) into: avariableName
115  from sashelp.class;
116  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


117
118  %put The macro variable Avariablename=&avariablename.;
The macro variable Avariablename=      19

@GN0001 wrote:

Hello team,

I have this:

proc sql;
select counts (*) into: avariableName from mytable;
quit;

Respectfully,

blue & blue


Count(*) basically counts observations

Kurt_Bremser
Super User

Using COUNT(*) causes SQL to read the whole dataset; it is much better (faster) to query the dataset metadata:

proc sql noprint;
select nobs (*) into: avariableName
from dictionary.tables
where libname = "WORK" and memname = "MYTABLE";
quit;
Tom
Super User Tom
Super User

What part don't you understand?

PROC SQL?

SELECT?

COUNT() function?
COUNT(*)?

INTO?

:?

FROM?


What do you think it does from the context of the program where it was used?

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!
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
  • 559 views
  • 1 like
  • 5 in conversation