This code is written in SAS (Statistical Analysis System) and...

September 4, 2025 at 09:29 PM

%if %sysfunc(exist(&outds)) %then %do; proc append base=&outds data=&cnt_ds force; run; %end; %else %do; data &outds; set &cnt_ds; run; %end;

This code is written in SAS (Statistical Analysis System) and is used for conditional appending or creating a dataset based on whether the target dataset (&outds) already exists.

Here’s what the code does:

  1. Check if the dataset &outds exists:

    • The macro %sysfunc(exist(&outds)) checks if the dataset specified by the macro variable &outds exists.
    • If it exists, the result is 1, and the code inside the first %do block is executed.
    • If it does not exist, the result is 0, and the code inside the %else %do block is executed.
  2. First Case (&outds exists):

    proc append base=&outds data=&cnt_ds force;
    run;
    
    • If &outds exists, the PROC APPEND procedure appends the dataset specified by &cnt_ds to the existing dataset (&outds).
    • The force option ensures that the append operation proceeds even if the variables between the datasets do not perfectly match (e.g., in structure or attributes).
  3. Second Case (&outds does not exist):

    data &outds;
        set &cnt_ds;
    run;
    
    • If &outds does not exist, the code creates a new dataset with the name &outds using the DATA step.
    • The SET statement reads and copies all observations from the dataset &cnt_ds into the dataset &outds.

Summary:

  • If the target dataset &outds already exists, it appends the contents of &cnt_ds to &outds.
  • If the target dataset &outds does not exist, it creates &outds and populates it with the contents of &cnt_ds.
Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node