BookmarkSubscribeRSS Feed
sas_Forum
Calcite | Level 5

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

4 REPLIES 4
Ksharp
Super User

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;

sas_Forum
Calcite | Level 5

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

Ksharp
Super User

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.

Haikuo
Onyx | Level 15

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 610 views
  • 3 likes
  • 3 in conversation