BookmarkSubscribeRSS Feed
deleted_user
Not applicable
How can I create a variable (say number of records) from one table to be used in a calculation in another table (without linking the tables).

For example, I have a table with 100 records.
In another table, I want to divide a number by those X records. In this case, X being 100.
Thanks.
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Your best choice is using SAS Macro variables. This is just one example. There are other ways of creating macro variables.
[pre]
proc sql;
select nobs into :cntobs
from dictionary.tables
where libname = "SASHELP" and
memname = "CLASS";
quit;

%let cntobs = &cntobs;
%put cntobs= &cntobs is the number of obs in SASHELP.CLASS;

data new;
set sashelp.shoes;
retain divideby &cntobs;
newnum = sales / divideby;
run;

ods listing;
proc print data=new (obs=5);
title "Using the Number of Obs ( &cntobs ) from CLASS to divide by in SHOES";
var region product sales divideby newnum;
run;
[/pre]

If you need more help understanding what this program is doing or how to use SAS Macro variables or if this examples does not suit your needs, your best bet for help is to contact SAS Tech Support.

cynthia

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 536 views
  • 0 likes
  • 2 in conversation