Hi,
I think having not programmed anything new lately has really deteriorated my skills.
I have a really long program. I want to create a secondary QA dataset which captures all the table names, observations numbers, variable numbers as the program is running. This way in each step, I can compare observation numbers to ensure that they all match. This needs to be automated which is why I am asking for help here.
How do I do this in a macro? I know how to set up macro variables to do this (see below). However, I cannot figure out how to do it in a dataset.
%MACRO OBSNVARS(DS);
%GLOBAL DSET NVARS NOBS;
%LET DSET=&DS;
/* OPEN DATA SET PASSED AS THE MACRO PARAMETER */
%LET DSID = %SYSFUNC(OPEN(&DSET)); /*1 IF DATASET EXISTS; 0 IF DATASET DOES NOT EXIST*/
/* IF THE DATA SET EXISTS, GET THE NUMBER OF OBSERVATIONS */
/* AND VARIABLES AND THEN CLOSE THE DATA SET */
%IF &DSID %THEN
%DO;
%LET NOBS =%SYSFUNC(ATTRN(&DSID,NOBS));
%LET NVARS=%SYSFUNC(ATTRN(&DSID,NVARS));
%LET RC = %SYSFUNC(CLOSE(&DSID));
%END;
/* OTHERWISE, WRITE A MESSAGE THAT THE DATA SET COULD NOT BE OPENED */
%ELSE %PUT OPEN FOR DATA SET &DSET FAILED - %SYSFUNC(SYSMSG());
%MEND OBSNVARS;
Would it be easier to hit SASHELP.VCOLUMN instead and retrieve that information?
Would it also make sense to pass two data set names in so it can compare the record counts and let you know if there's an issue?
@lei wrote:
Hi,
I think having not programmed anything new lately has really deteriorated my skills.
I have a really long program. I want to create a secondary QA dataset which captures all the table names, observations numbers, variable numbers as the program is running. This way in each step, I can compare observation numbers to ensure that they all match. This needs to be automated which is why I am asking for help here.
How do I do this in a macro? I know how to set up macro variables to do this (see below). However, I cannot figure out how to do it in a dataset.
%MACRO OBSNVARS(DS); %GLOBAL DSET NVARS NOBS; %LET DSET=&DS; /* OPEN DATA SET PASSED AS THE MACRO PARAMETER */ %LET DSID = %SYSFUNC(OPEN(&DSET)); /*1 IF DATASET EXISTS; 0 IF DATASET DOES NOT EXIST*/ /* IF THE DATA SET EXISTS, GET THE NUMBER OF OBSERVATIONS */ /* AND VARIABLES AND THEN CLOSE THE DATA SET */ %IF &DSID %THEN %DO; %LET NOBS =%SYSFUNC(ATTRN(&DSID,NOBS)); %LET NVARS=%SYSFUNC(ATTRN(&DSID,NVARS)); %LET RC = %SYSFUNC(CLOSE(&DSID)); %END; /* OTHERWISE, WRITE A MESSAGE THAT THE DATA SET COULD NOT BE OPENED */ %ELSE %PUT OPEN FOR DATA SET &DSET FAILED - %SYSFUNC(SYSMSG()); %MEND OBSNVARS;
Would it be easier to hit SASHELP.VCOLUMN instead and retrieve that information?
Would it also make sense to pass two data set names in so it can compare the record counts and let you know if there's an issue?
@lei wrote:
Hi,
I think having not programmed anything new lately has really deteriorated my skills.
I have a really long program. I want to create a secondary QA dataset which captures all the table names, observations numbers, variable numbers as the program is running. This way in each step, I can compare observation numbers to ensure that they all match. This needs to be automated which is why I am asking for help here.
How do I do this in a macro? I know how to set up macro variables to do this (see below). However, I cannot figure out how to do it in a dataset.
%MACRO OBSNVARS(DS); %GLOBAL DSET NVARS NOBS; %LET DSET=&DS; /* OPEN DATA SET PASSED AS THE MACRO PARAMETER */ %LET DSID = %SYSFUNC(OPEN(&DSET)); /*1 IF DATASET EXISTS; 0 IF DATASET DOES NOT EXIST*/ /* IF THE DATA SET EXISTS, GET THE NUMBER OF OBSERVATIONS */ /* AND VARIABLES AND THEN CLOSE THE DATA SET */ %IF &DSID %THEN %DO; %LET NOBS =%SYSFUNC(ATTRN(&DSID,NOBS)); %LET NVARS=%SYSFUNC(ATTRN(&DSID,NVARS)); %LET RC = %SYSFUNC(CLOSE(&DSID)); %END; /* OTHERWISE, WRITE A MESSAGE THAT THE DATA SET COULD NOT BE OPENED */ %ELSE %PUT OPEN FOR DATA SET &DSET FAILED - %SYSFUNC(SYSMSG()); %MEND OBSNVARS;
ABSOLUTELY. Thank you.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.