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,
SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.
Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.