There are times when you need to take data from a database query and put it into a SAS macro variable. Today was one of those times. It would be wrong not to share the example.
This example uses SAS 9.4 and Oracle but it applies to most any database (DB2, Netezza, Teradata, Hadoop (Hive), Microsoft SQL Server, MySQL, PostgreSQL) and SAS/ACCESS product.
libname myora oracle path=myora user=myuser password=mypassword;
data myora.cars;
set sashelp.cars;
run;
proc sql;
connect using myora;
select count(*) into :mycount from connection to myora
(select * from cars);
quit;
%put "mycount=&mycount";
The count(*) value is contained in the &mycount SAS macro variable. You can see it in the SAS log.
8 %put "mycount=&mycount";
"mycount= 428"
Hope this helps, Jeff
... View more