SAS macros

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

SAS macros

I have a text file with the below format.

patient_id|desc

1|active

34|closed

33|joined on 23-apr-12

patient|01JAN2011|3

The first row is a header variable. The last row is a trailer with the file name, date the text file was sent and the record count.

I have loaded the data into a sas dataset. In that process , I also want to check if the record count in the trailer matches with the data that gets loaded into the sas dataset. I skip the trailer record when I load my data into the patient sas dataset.

If i could incorporate this logic into a macro and read the macro into the main sas job that loads the data into a dataset, it would be better. I need to do this check on 7 files.

Please advise as I am a beginner in sas and never used macros....


Accepted Solutions
Solution
‎04-17-2012 04:26 PM
Occasional Contributor
Posts: 9

Re: SAS macros

Posted in reply to JasonDiVirgilio

All Replies
Super User
Super User
Posts: 7,074

Re: SAS macros

Doesn't sound like a macro issue.

For example here is a data step to read your example data.

data want ;

  infile cards firstobs=2 dlm='|' truncover ;

  input patient ?? :9. status $40. ;

  if patient ne . then do;

     recordno+1;

     output;

  end;

  else do;

    put _infile_ / recordno= ;

  end;

cards;

patient_id|desc

1|active

34|closed

33|joined on 23-apr-12

patient|01JAN2011|3

run;

Occasional Contributor
Posts: 9

Re: SAS macros

Thanks Tom. I have already read the txt file and created a sas dataset. I want to write a macro to do the quality check by comparing the trailer record count to the number of records in the dataset after the load. How do i check this?

Regular Contributor
Posts: 233

Re: SAS macros

Is the text file in Windows or Unix server?

Occasional Contributor
Posts: 9

Re: SAS macros

The txt file is on a unix server. I do know how to load the txt file into a dataset. I want to know how to compare and validate the dataset records count with the trailer record count (here trailer count = 3) using a sas macro.

Contributor
Posts: 46

Re: SAS macros

When you read the trailer record, create a macro variable using CALL SYMPUT('yourmacrovar', rowcountvar);

Create yourself a little macro called NumObs to check the number of observations in a dataset:

  %macro numobs(dsn);
        %global numobs;

        %let dsid=%sysfunc(open(&dsn));
        %let numobs=%sysfunc(attrn(&dsid,nobs));
        %let rc=%sysfunc(close(&dsid));
  %mend numobs;

Then compare the two macro variables:

  %if &yourmacrovar=&numobs %then %let validated=YES;

  %else %let validated=NO;


Solution
‎04-17-2012 04:26 PM
Occasional Contributor
Posts: 9

Re: SAS macros

Posted in reply to JasonDiVirgilio

thanks

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 571 views
  • 4 likes
  • 4 in conversation