Help using Base SAS procedures

Q1.Drop Datasets having 0 obs. Q2 Rename the first obs to Datasets

Reply
Frequent Contributor
Posts: 140

Q1.Drop Datasets having 0 obs. Q2 Rename the first obs to Datasets

RenaeQuery 1:


i am Having Datasets in work some are having 0 obs how can i drop all the tables

Ex:
Dset  obs
Name1  10 obs
Name2  0 obs
Name3  40 obs
Name4  0 obs
ID1    0 obs
id2    10 obs

i want to drop the obs with 0 records as i dont know how many datasets will be there
and with Differnt names


Query 2:
   
I am having SAS DAtasets ex: x,y,z in this the first obs will have the dataset name i
want to rename the dataset name x to the name existing in first obs.


In the above ex i gave x,y,z, but i dont know the exact names how can i do it.

Dataset x;
obs
1 Main Dataset

Super User
Posts: 9,671

Re: Q1.Drop Datasets having 0 obs. Q2 Rename the first obs to Datasets

Q1:

data test;
input x;
datalines;
1
.
.
2
.
3
;
run;
data zero;
 set test;
 stop;
run;
data zero1;
 set test;
 stop;
run;

proc sql; 
select distinct memname into : list separated by ','
 from dictionary.tables
  where libname='WORK' and nobs=0;

drop table &list ;
quit;



Q2:

data x;name='asa';run;
data y;name='asdsda';run;
data z;name='dsda';run;


proc sql noprint;
 select cats(' x=',name) into : x from x(obs=1);
 select cats(' y=',name) into : y from y(obs=1);
 select cats(' z=',name) into : z from z(obs=1);
quit;
proc datasets library=work nolist;
change  &x &y &z ;
quit;

Frequent Contributor
Posts: 140

Re: Q1.Drop Datasets having 0 obs. Q2 Rename the first obs to Datasets

Ksharp actually i am ahving 100 datsets in that condition how can i do it as i dont know the datasets it many

be like data1  up to data200 ,a,b,c,pdf,jkh  like dataset names in this how can i do

Super User
Posts: 9,671

Re: Q1.Drop Datasets having 0 obs. Q2 Rename the first obs to Datasets

use dictionary.members to query the table name and wrap them into a marco variable by SQL. It is easy.

Somebody will give you example. I have to leave now.

Respected Advisor
Posts: 3,124

Re: Q1.Drop Datasets having 0 obs. Q2 Rename the first obs to Datasets

Well, This is my attempt trying to be somebody.

data _x;name='asa';run;

data _y;name='asdsda';run;

data _z;name='dsda';run;

proc sql NOPRINT;

select cats(memname,'(obs=1)') into :memname SEPARATED BY ' ' from dictionary.tables where libname='WORK';

data have;

length name $10.;

set &MEMNAME indsname=dsn;

dsname=scan(dsn,-1,'.');

run;

proc sql NOPRINT;

select cats(dsname,'=',name) into: change separated by ' ' from have;

proc datasets library=work nolist;

change &change;

quit;

Thanks, Ksharp for the insight!

Haikuo

Ask a Question
Discussion stats
  • 4 replies
  • 185 views
  • 3 likes
  • 3 in conversation