SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
data Porto;
input apple lemon orange;
datalines;
1 2 3
2 3 4
3 4 5
1 5 5
3 0 0
6 0 0
7 0 0
run;

PROC SQL;
create table result as
SELECT DISTINCT count(*) into :total
FROM Porto;
QUIT;

proc print data=result;
run;

if I skip the line "create table result as" Is the code not gonna to save any output? is it just gonna showing in the log whatever is identified? 

 

what does count(*) into :total means? is it just total number of rows in table Porto? what is :total? this is looking very strange I tried the code and the output is very strange too...

 

HeatherNewton_0-1647146513271.png

 

1 REPLY 1
Kurt_Bremser
Super User

SELECT INTO is the method to create macro variables from SQL. So your step creates macro variable &total which holds the count of all observations in the dataset porto.

The DISTINCT in your query serves no purpose (there is only one count anyway), so remove it. Without a CREATE TABLE, only the macro variable and the print output are created. When the sole purpose of the step is to create the macro variable, run PROC SQL with the NOPRINT option.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 324 views
  • 1 like
  • 2 in conversation