How to run part of macro based on number of observations in work file in SAS

ShrewdOperator

I'm pretty new to doing macros on SAS so apologies in advance if my questions seems basic.

I'm looking to execute part of a macro if there are a minimum number of observations found in temporary work file.

If there are a minimum number of observations, the macro should execute a proc export of that temporary work file, otherwise it will just produce an error message on the log.

I'm not sure what I'm doing wrong, the temporary work file has more than 1 observation and I want the macro to run, however it produces the error message as if it has less than the minimum.

Below is the code that I've created so far - any help you have to offer will be greatly welcomed.

data original_data;
set data.dataset;

keep column1 column2 column3 ;
run;


%macro test_macro;

%let dsid=%sysfunc(open(work.original_data));
%let nobs=%sysfunc(attrn(&dsid,nobs));
%let dsid=%sysfunc(close(&dsid));


%if &nobs >1 %then %do;
%put ERROR: No observations counted;
%return
%end

%else %do;

proc export data=submissions
        outfile='C:\Users\myusername\Desktop\test.csv'
        DBMS=csv replace; 
run;

%end;

%mend test_macro;

%test_macro
Reeza
  1. Missing semicolons on RETURN and END statements
  2. Logic is reversed. You're putting the error message if you have more than one observation. Flip your code so that you export if you have more than one observation.
  3. Use %EVAL() for comparisons just to be careful. Character comparisons can lead to unexpected results.
options mprint symbolgen;

%macro test_macro;
    %let dsid=%sysfunc(open(work.original_data));
    %let nobs=%sysfunc(attrn(&dsid, nobs));
    %let dsid=%sysfunc(close(&dsid));
    %put &nobs;
    *if more than one observation;

    %if %eval(&nobs > 1) %then
        %do;

            proc export data=sashelp.class outfile='/home/fkhurshed/test.csv' DBMS=csv 
                    replace;
            run;

        %end;
    %else
        %do;
            %put ERROR: No observations counted;
            %return;
        %end;
%mend test_macro;

%test_macro;

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

How to print the number of observations into an external file - selection with where applied?

Rename a external file in a SAS macro

Create a new variable based on modal number of observations

How to count the number of two observations binary combinations?

How to rename observations based upon frequency in R?

How to classify observations based on their covariates in dataframe and numpy?

How to use cycles in sas macro data step

How to limit number of Months in SAS

How to conditionally change a small part of a Rust macro?

How to define a part of class name as macro?

Is it possible for a macro to generate code based on the content of a file?

How to limit go routines based on number of file descriptors

How to sort text file based on number after first letter

How to put the number of observations at the bottom of gtsummary regression table?

How to increase the number of observations in xts object by taking previous value?

Based on a specific number, how to I work out the % increase required, using the % decrease which will be applied, to get back to that number?

How to concatenate string and numeric SAS Macro and use it in where statement

How to read multiple files with date in the names using a macro into SAS

How can I store a macro variable value into SAS dataset?

Count the number of observations

Macro Formula to run in Selected cell and use cells based of the selected

Macro bootstrap no SAS

Numeric Macro in SAS

Macro de filtro Sas

How to run a macro in different excel worksheets? It is not looping

How to run macro from another workbook

SAS PROC SQL - How to convert string to number

How to include only three-part file version (without fourth revision number) to the AppVersion value in Inno Setup

How do I write output of a command to multiple text files where the file names are based on part of the command output?

TOP lista

  1. 1

    R Shiny: use HTML em funções (como textInput, checkboxGroupInput)

  2. 2

    O Chromium e o Firefox exibem as cores de maneira diferente e não sei qual deles está fazendo certo

  3. 3

    Como assinar digitalmente um documento PDF com assinatura e texto visíveis usando Java

  4. 4

    R Folheto. Dados de pontos de grupo em células para resumir muitos pontos de dados

  5. 5

    Gerenciar recurso shake de Windows Aero com barra de título personalizado

  6. 6

    Como obter dados API adequados para o aplicativo angular?

  7. 7

    UITextView não está exibindo texto longo

  8. 8

    Por que meus intervalos de confiança de 95% da minha regressão multivariada estão sendo plotados como uma linha de loess?

  9. 9

    Acessando relatório de campanhas na AdMob usando a API do Adsense

  10. 10

    Usando o plug-in Platform.js do Google

  11. 11

    Como posso modificar esse algoritmo de linha de visada para aceitar raios que passam pelos cantos?

  12. 12

    Dependência circular de diálogo personalizado

  13. 13

    Coloque uma caixa de texto HTML em uma imagem em uma posição fixa para site para desktop e celular

  14. 14

    iOS: como adicionar sombra projetada e sombra de traço no UIView?

  15. 15

    Como usar a caixa de diálogo de seleção de nomes com VBA para enviar e-mail para mais de um destinatário?

  16. 16

    Tabela CSS: barra de rolagem para a primeira coluna e largura automática para a coluna restante

  17. 17

    How to create dynamic navigation menu select from database using Codeigniter?

  18. 18

    Converter valores de linha SQL em colunas

  19. 19

    ChartJS, várias linhas no rótulo do gráfico de barras

  20. 20

    用@StyleableRes注释的getStyledAttributes。禁止警告

  21. 21

    não é possível adicionar dependência para com.google.android.gms.tasks.OnSuccessListener

quentelabel

Arquivo