BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sivastat08
Pyrite | Level 9

 

Hi ,

By referring this site "Get a list of dataset names in a directory/library" i got an output of sas Library with column name.

and referring Proc Contents i can able to get no of rows and columns but i am  unable to get distinct rows for each data sets . I am looking for distinct rows of each data sets and referring  'FileName' name column dynamically.Attached sample data.

Can help on this.

 

Thanks,

Siva

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The table SASHELP.VTABLE always has this information.

 

So, if you are interested in all SAS data sets in a library named PAIGE

 

proc print data=sashelp.vtable(where=(libname='PAIGE' and memtype='DATA'));
    id memname;
    var nobs nvar;
run;
--
Paige Miller

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

The table SASHELP.VTABLE always has this information.

 

So, if you are interested in all SAS data sets in a library named PAIGE

 

proc print data=sashelp.vtable(where=(libname='PAIGE' and memtype='DATA'));
    id memname;
    var nobs nvar;
run;
--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You would need to do something like:

data _null_;
  set sashelp.vtable (where=(libname="<yourlib>"));
  call execute(cats('proc sort data=<yourlib>.',memname,' out=dist_',memname,' nodupkey; by _all_; run;'));
run;

Replace <libname> with your library.  The above will run a proc sort on all the datasets, then you can take from sashelp.vtable number of rows, just like the other datasets.

sivastat08
Pyrite | Level 9

Hi RW ,Thanks for Help.

 

Below code is selecting the data set names , but it's throwing an error.Could you please help on fixing this.Below are Error logs.

 

/*Code*/

 

data _null_;
set sashelp.vtable (where=(libname="STSTGTBL"));
call execute(cats('proc sort data=STSTGTBL.',memname,' out=dist_',memname,' nodupkey; by _all_; run;'));
run;

 

/*Error1*/

 

24 data _null_;
25 set WORK.QUERY_FOR_AAA (where=(Library_Name="STSTGTBL"));
26 call execute(cats('proc sort data = STSTGTBL. ',Table_Name,'out= dis_',Table_Name,'nodupkey; by _all_; run;'));
27 run;

NOTE: There were 131 observations read from the data set WORK.QUERY_FOR_AAA.
WHERE Library_Name='STSTGTBL';
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1 + proc sort data = STSTGTBL.ABSENTEEISM_NGout= dis_ABSENTEEISM_NGnodupkey; by _all_; run;
_
22
76

ERROR 22-322: Syntax error, expecting one of the following: DATA, DUPOUT, IN, OUT, SIZE, SORTSEQ, SORTSIZE, T, TECH, TECHNIQUE,
UNIOUT, UNIQUEOUT.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


NOTE: Line generated by the CALL EXECUTE routine.
2 The SAS System 09:21 Tuesday, March 5, 2019

2 + proc sort data = STSTGTBL.ACTIVEDLYSNAPTILL30SEP2018_0000out= dis_ACTIVEDLYSNAPTILL30SEP2018_0000nodupkey; by _all_;
run;
_
22
76
ERROR: Invalid data set name STSTGTBL.ACTIVEDLYSNAPTILL30SEP2018_0000out.

ERROR 22-322: Syntax error, expecting one of the following: DATA, DUPOUT, IN, OUT, SIZE, SORTSEQ, SORTSIZE, T, TECH, TECHNIQUE,
UNIOUT, UNIQUEOUT.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, yes, I hadn't noticed as I didn't have anything to test it on.  Its a simple change:

data _null_;
  set sashelp.vtable (where=(libname="STSTGTBL"));
  call execute(cat('proc sort data=STSTGTBL.',memname,' out=dist_',memname,' nodupkey; by _all_; run;'));
run;

Note, instead of using cats() which strips blanks from start and end of strings, I use cat().

Peter_C
Rhodochrosite | Level 12
Is distinct counting to
apply distinct across all columns in a table
Or distinct counts for each column
(The second approach might be useful too)
sivastat08
Pyrite | Level 9

 

I changed it before running ' out=dist_'  i tried running instead of out= but i am getting below error 

/*Code:*/

data _null_;
set sashelp.vtable (where=(libname="STSTGTBL"));
call execute(cats('proc sort data=STSTGTBL.',memname,'out=',memname,' nodupkey; by _all_; run;'));
run;

 

 

23 GOPTIONS ACCESSIBLE;


24 data _null_;
25 set sashelp.vtable (where=(libname="STSTGTBL"));
26 call execute(cats('proc sort data=STSTGTBL.',memname,'out=',memname,' nodupkey; by _all_; run;'));
27 run;

NOTE: There were 4 observations read from the data set SASHELP.STSTGTBL.
WHERE libname='VALIB';
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds

NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1 + proc sort data=VALIB.ATTRLOOKUPout=ATTRLOOKUPnodupkey; by _all_; run;
_
22
76

ERROR 22-322: Syntax error, expecting one of the following: DATA, DUPOUT, IN, OUT, SIZE, SORTSEQ, SORTSIZE, T, TECH, TECHNIQUE,
UNIOUT, UNIQUEOUT.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


NOTE: Line generated by the CALL EXECUTE routine.
2 The SAS System 11:53 Tuesday, March 5, 2019

2 + proc sort data=STSTGTBL.CENTLOOKUPout=CENTLOOKUPnodupkey; by _all_; run;
_
22
76

ERROR 22-322: Syntax error, expecting one of the following: DATA, DUPOUT, IN, OUT, SIZE, SORTSEQ, SORTSIZE, T, TECH, TECHNIQUE,
UNIOUT, UNIQUEOUT.

ERROR 76-322: Syntax error, statement will be ignored.

Peter_C
Rhodochrosite | Level 12
Errors in generated cide are occurring at

data=VALIB.ATTRLOOKUPout=ATTRLOOKUPnodupkey; by _all_; run;
_
ERROR 22-322: Syntax error, expecting one of the following: DATA, DUPOUT, IN, OUT, SIZE, SORTSEQ, SORTSIZE, T, TECH, TECHNIQUE,
UNIOUT, UNIQUEOUT.


later at
2 + proc sort data=STSTGTBL.CENTLOOKUPout=CENTLOOKUPnodupkey; by _all_; run;

Both cases caused by lack of space before out= and nodupkey

Peter_C
Rhodochrosite | Level 12
If you cannot rearrange the syntax to ensure only a semicolon follows memname, one possibility that might work is to place something to act like a hard blank before out= and nodupkey. I think the syntax
'%str( ) out= ' and
'%str( ) nodupkey; by _all_; run;'

might do it, as long as these have single not double quotes
(or the blank in %( ) would resolve to early)
sivastat08
Pyrite | Level 9

Thanks A lot Peter. I have used the above mentioned  syntax  '%str( ) out= ' and '%str( ) nodupkey; by _all_; run;' .Also The Code is running and generating Outputs.But output data sets are limited to 50 only.

 

Here is my code:

 

data _null_;
set sashelp.vtable (where=(libname="MAPSSAS"));
call execute(cats('proc sort data=MAPSSAS.',memname,'%str() out=out_',memname,'%str() nodupkey; by _all_; run;'));
run;

 

by using this code

proc print data=sashelp.vtable(where=(libname='PAIGE' and memtype='DATA'));
    id memname;
    var nobs nvar;
run;

i am getting output of memname ,Nobs and Nvar, Also i need No of distinct rows for each data sets.will you please help me out.

 

memnamenobsnvarNdistinct
AFGHANI2294 
AFGHANIS26446 
AFRICA528248 
AFRICA26110 
ALGERIA16176 
ALGERIA294 
ANDORRA2036 
ANDORRA214 
ANOMALY1210 
ANTARCT2510 
ANTARCTI180718 
ARGENTI2249 
ARGENTIN38526 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 4812 views
  • 7 likes
  • 4 in conversation