Skip to content

Your daily loop

Every SAS programmer repeats one loop all day: write, run, read the log, look at the data, fix. This chapter makes each part shorter. You have used the basics since chapter 2. The keys are also on the cheat sheet.

You do not have to run a whole program to test one change.

Run modeKeyWhat runsUse it when
RunF4, Cmd/Ctrl+Enter; F3, F8 as in SASthe selection, else the whole programyou start, or you changed many places
Run To LineCtrl+Alt+Upfrom the top down to the cursor lineyou want the data as it is at one point of a long program
Run From LineCtrl+Alt+Downfrom the step at the cursor to the endthe first part is done and its WORK data sets exist
Run Step▷ menu in the title barthe step, SQL statement, macro definition or macro call at the cursoryou changed one step
Run As MacroCommand Palette%DO/%IF code selected inside a macro; it asks for the parametersyou test one part of a macro
Resolve CodeCtrl+Alt+Rshows the code a macro call generates, formatted, beside your programyou want to see what a macro really does
SAS commandCtrl+Alt+Cone line of SAS from a small box with historya quick %PUT &=sysver.; or WSAVE ALL
Run in TemplateCommand Paletteyour code wrapped in a template, for example ODS_RTF for an RTF fileyou need the output in a file

A step is never cut in half: Run To Line runs the whole step that contains the cursor line.

09_1_adsl.sas builds ADSL in numbered steps: adsl_010 to adsl_040, then adsl.

  1. Put the cursor on the line /* Step 040: population flags from SUPPDM, N when no record */ and press Ctrl+Alt+Up. What you should see: the Libraries tab lists ADSL_010, ADSL_020 and ADSL_030, but not yet ADSL_040.
  2. Change something in step 040, put the cursor in it, and choose Run Step in the ▷ menu. Only that step runs.
  3. Put the cursor on the call %count_by(data=refadm.adae, ...) at the bottom of 08_2_count_by.sas (run the program once first, so SAS knows the macro) and press Ctrl+Alt+R. What you should see: beside your program, the DATA step and the PROC SQL that the call generates, with refadm.adae, trtan, aesev and the WHERE filled in.
Run To Line (Ctrl+Alt+Up) with the cursor on the Step 040 comment

Run To Line (Ctrl+Alt+Up) with the cursor on the Step 040 comment: everything above it ran, so the Libraries tab lists ADSL_010 to ADSL_030, and the log ends with “Run to line 50”.

While SAS runs, the status bar shows SAS running 0:12 and a Stop SAS button. One click stops the code, like Ctrl+Break in SAS. Your session, WORK data sets and macro variables stay.

The SAS Log opens below your program. ERROR is red, WARNING yellow, NOTE blue. ▲ Error and Error ▼ jump from problem to problem, and a click on an ERROR moves the cursor to the line in your program that caused it. F2 clears the log and the output.

Three places show problems:

TabWhat it shows
SAS Logthe whole log of every run
Problemsevery ERROR, WARNING and important NOTE, each with its program line; the line also has a squiggle
Suspicious Logonly what a QC log check looks for: ERROR, WARNING and NOTEs such as uninitialized, Missing values were generated, repeats of BY values and Invalid data

The Chapter 2 screenshot shows the Suspicious Log after a program with four such NOTEs.

Your team’s own rules. In the settings (Cmd+, or Ctrl+,), datastepStudio.log.suspiciousNotes takes more patterns, for example Table WORK\.\w+ created, with 0 rows. A message you know is harmless goes into datastepStudio.log.suspiciousIgnore.

WhereWhatKeys
Libraries (right)your librefs and their data sets; ▸ shows the variables with type and label; a click on a variable opens the data set at that columndouble-click opens a data set
F12opens the data set the last step createdF12
Variables (right)the macro variables of your session; filter them, or add name=value
Options (right)every system option by group; click one to change it, ↺ puts the old value back, 🔍 finds an option
SAS Output (bottom)the listing of PROC PRINT, PROC FREQ and the other proceduresCtrl+Alt+O
Created Files (bottom)files your run wrote, such as an RTF

Change LINESIZE in two steps: open Options, click 🔍, type linesize, press Enter, type the new value, press Enter. The row then shows (changed, was 132).

Drag any tab where you like. Type WSAVE ALL in the SAS command box (Ctrl+Alt+C) and the same tabs open the next time SAS connects. F9 opens the Keys tab: every command with its keys, and + to give a command your own key.

Run in Batch runs a folder of programs, one after the other, while you keep working.

  1. In the Explorer, right-click a folder (or select several programs) and choose Run in Batch.
  2. Keep working: your own session is not touched.
  3. When it is done, a message tells you how it went. Show Summary opens the overview; the second button opens the first log with errors.

Programs run in the order of their names, numbers by value (2_adae.sas before 10_adlb.sas). Each program gets a fresh SAS session: empty WORK, no macro variables from before. Its .log and .lst are written next to it. So a program that passes in batch really stands on its own. Section 26.5 uses this on the book’s programs.

Programs on your computer. Open your folder in VS Code and press F4. Before each run, DataStep Studio copies the files that changed to a folder in your SAS home, ~/datastep-studio/<project>-<id>, and runs the program there. A run without changes costs a few milliseconds.

Relative paths just work: %INCLUDE "10_2_0_bds_macros.sas"; in a program of this book finds the file next to it. Files that SAS writes come back to your computer; data sets stay on the server. The status bar shows the server folder, for example ☁ study-3f2a9c1e.

Programs on the server. DataStep Studio: Open SAS Server Folder opens a second window on your SAS OnDemand home: open, edit, save and create files there as usual. The first time, VS Code asks whether you trust the folder: click Trust…, then Trust.

Both side by side. DataStep Studio: Open File Manager shows a folder of your computer on the left and a server folder on the right. Space marks files, F5 then Enter copies them to the other side, and F6 then Enter moves them. It is a Professional feature, free during Early Access at the time of writing.

Exercise 20-1. Open 04_first_last.sas. Run only the PROC SORT with Run Step, then press F12. How many rows does WORK.AE2 have?

Exercise 20-2. Add the pattern Table WORK\.\w+ created, with 0 rows to your Suspicious Log rules. Write a PROC SQL with WHERE 0 and run it. Does the Suspicious Log flag it?

Exercise 20-3. Change LINESIZE to 100 in the Options tab, run a PROC PRINT, then put the old value back with ↺.

Answers: Chapter 20 answers.

Next: look at data without writing code.