BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ani7
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
8 REPLIES 8
Ksharp
Super User

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
Ani7
Obsidian | Level 7

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.

Kurt_Bremser
Super User

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.

Kurt_Bremser
Super User

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).

Ani7
Obsidian | Level 7
Ah I was afraid of this. Since this answers my question, I am accepting this as a solution.
FreelanceReinh
Jade | Level 19

Hello @Ani7,

 

  1. The "number of observations read from the last data set that was closed by the previous procedure or DATA step" is contained in the SYSNOBS automatic macro variable.
  2. You can read text from and write text to the clipboard by means of the CLIPBRD access method of the FILENAME statement.
  3. Code snippets to be submitted can be assigned to a keyboard shortcut in the KEYS window.

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):

clipbrd.png

(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 */

 

Ani7
Obsidian | Level 7
This is potentially exactly what I'm looking for. Is the KEYS window only available for Base SAS and not EG?
FreelanceReinh
Jade | Level 19

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 810 views
  • 1 like
  • 4 in conversation