I'm not sure if SAS (or any other program) has this capability but I was wondering if I created a dataset like this:
data want;
set have;
run;
and if the generated dataset had 5,000 observations, is it possible to automatically generate a line at the bottom of that code with the number of observations in the dataset like this?
data want;
set have;
run;
/* obs = 5000 */
If not, is it possible to write a macro that I put at the end of every data step that would count the number of observations in that dataset and copy it to the clipboard so that I can just paste /* obs = 5000 */ directly to the editor?
Copying to the clipboard is not available from code, as in most situations the SAS session won't even have a clipboard (batch mode, or workspace server from SAS Studio or EG).
Check LOG :
791 data air; 792 set sashelp.air; 793 run; NOTE: There were 144 observations read from the data set SASHELP.AIR. NOTE: The data set WORK.AIR has 144 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Right so my question is if there's a way to pull that "144 observations" string into the code editor in a form similar to what is outlined in my original post.
With a simple step like that, you can do this:
data want;
if _n_ = 1 then put "obs=" nobs;
set have nobs=nobs;
run;
This will put a number into the log for copy/pasting even if have is empty.
Depending on the complexity of your actual logic, you may have to count every output and put when the step finishes.
Copying to the clipboard is not available from code, as in most situations the SAS session won't even have a clipboard (batch mode, or workspace server from SAS Studio or EG).
Hello @Ani7,
Putting these three ideas together, you could open the KEYS window (press F9 or enter KEYS into the command line [assuming Windows SAS]) and create a new keyboard shortcut, for example Alt F3, as shown below (highlighted):
(To make this key definition permanent you need write access to your SASUSER.PROFILE.)
Now, after submitting a DATA step like
data test;
set sashelp.cars;
where horsepower>100;
run;
(or a corresponding PROC step, e.g. using PROC SQL) you would press the keyboard shortcut (Alt F3 in the example) and then paste the desired text from the clipboard into the Enhanced Editor (or wherever you want).
/* obs = 425 */
I never use SAS EG, but in his blog Chris Hemedinger suggested to use an external tool called AutoHotkey (which I haven't used either) as a substitute for the missing KEYS window: https://blogs.sas.com/content/sasdummy/2017/07/17/sas-eg-key-mappings/
Not sure if this helps, sorry.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.