How to identify and delete empty datasets in an elegant manner

sas

    Sponsored Links

    Next

  • 1. Reshaping the data to run the simple correlation analysis
    Hello there, I have a data set looks like: F1 F2 V1 1 1 0.1 1 2 0.3 1 3 0.5 2 1 0.56 2 2 0.99 2 3 0.78 3 1 0.84 3 2 0.83 3 3 0.65 I will like to run the correlation on each pair of F1 group which means that for F1=1, I will run its v1 values with the values when F1=2 and also the values when F1=3. Then, I will also run the values for F1=2 with the values when F1=1 and also with the values when F1=3 Same for the values for F1=3 with values when F1=1 and with the values when F1=2; In brief, the data to be prepared for the proc corr analysis should be like: 1 2 0.3 2 1 0.56 1 3 0.5 2 3 0.78 1 2 0.3 3 1 0.84 1 3 0.5 3 2 0.83 2 1 0.56 1 2 0.3 2 3 0.78 1 3 0.5 2 1 0.56 3 1 0.84 2 3 0.78 3 2 0.83 3 1 0.84 1 2 0.3 3 2 0.83 1 3 0.5 3 1 0.84 2 1 0.56 3 2 0.83 2 3 0.78 I was wondering that is there an efficient way to do it? Any thoughts? Please let me know if possible. Thanks in advance!!! Henry
  • 2. Missing value with e8601dt. format
    Hi there, When options missing is set to blank, a missing datatime value converted by put and datetime. format will generate a blank string, but not the case for e8601dt. format, which generate a '.'. This is at least an inconsitency. I would even call it a bug, since ISO8601 need a blank string instead of a '.': 1 options missing=' '; 2 data _null_; 3 dt=today(); 4 iso=put(dt,e8601dt.); 5 put iso=; 6 dt=.; 7 iso=put(dt,e8601dt.); 8 put iso=; 9 dtm=put(dt,datetime.); 10 put dtm=; 11 run; iso=1960-01-01T05:03:44 iso=. dtm= Ya
  • 3. Cluster / SE correction in SAS? + FIML in SAS
    I am running regressions, possibly GLM later and I have data (children) nested in schools. My research question does not include the school effects per se, but I do want to correct my standard errors for this clustering. I did this through the cluster optio in MPlus, but I want to do all my assumption checks - which MPlus cannot do. Can I fix this through fixed-effects? Maybe some other way? Which SAS procedure can do this for me? Additionally, can this procedure also do FIML? (The clustering problem is much more important than FIML) Thanks Igor Holas Graduate Student Human Development & Family Sciences and Population Research Center Seay 2.442 University of Texas at Austin 1 University Station - A2702 Austin, TX 78712 c: 440.281.3623 o: 512.232.1964 f: 512.475.8662 Igor Holas Graduate Student Human Development & Family Sciences and Population Research Center Seay 2.442 University of Texas at Austin 1 University Station - A2702 Austin, TX 78712 c: 440.281.3623 o: 512.232.1964 f: 512.475.8662
  • 4. Filling Blanks Between 2 Values
    hi, i have a dataset as follows - date present 01AUG2009 02AUG2009 03AUG2009 04AUG2009 Y 05AUG2009 06AUG2009 07AUG2009 08AUG2009 09AUG2009 Y 10AUG2009 11AUG2009 Y 12AUG2009 is there a way i can fill in the blanks between the first and last dates where a Y is recorded? thanks, nick

How to identify and delete empty datasets in an elegant manner

Postby Shelley.Baxter » Sun, 26 Mar 2006 02:58:01 GMT

Would this be a proc sql approach with the vtable?

Shelley S. Baxter, Ph.D.
Boeing Corp.
            509-637-4500

Re: How to identify and delete empty datasets in an elegant manner

Postby Jiann-Shiun.Huang » Sun, 26 Mar 2006 03:47:32 GMT

Shelley:

  If your datasets are "ORDINARY DATASET" as mentioned in Jack's paper,
then the following code should work for you.  You need to change
LibraryName to your libname without any quotation.

%let MyLib=%upcase(LibraryName);  /*Without any quote*/
proc sql noprint;
  select memname into :NameList separated by ' '
  from sashelp.vtable
  where libname="&MyLib" and nobs eq 0;
quit;

%put &NameList;

%macro droptbl(lib,nooblist);
  %let filecnt=%eval(%sysfunc(count(&nooblist,%str( )))+1);
  %put &filecnt;
  proc sql;
    %do i=1 %to &filecnt;
          %let dataset=%scan(&nooblist,&i);
          drop table &lib..&dataset;
    %end;
  quit;
%mend droptbl;

%droptbl(&MyLib,&NameList)
run;


J S Huang
1-515-557-3987
fax 1-515-557-2422

That's would I would do, if I knew the provenance of the data sets.
I'd probably use dictionary.tables rather than sashelp.vtable - it's
supposedly more efficient.

You do have to know how your data sets were created and modified -
there are some circumstances under which the observation count in
dictionary.tables will not be correct.  See my paper How Many
Observations Are In My Dataset?" at

< http://www.**--****.com/ ;.








---
Jack Hamilton
Sacramento, California

Re: How to identify and delete empty datasets in an elegant manner

Postby joewhitehurst » Sun, 26 Mar 2006 04:45:24 GMT

Or, you might consider the folllowing simple SAS Component Language program.

length memname $32;
init:
  submit continue;
     proc contents data=newtable._all_ dir noprint out=lib_contents;
     run;
  endsubmit;
lib_contents_dsid=open('lib_contents','i');
do until(fetch(lib_contents_dsid)^=0);
   temp_dsid=open('sashelp.'||memname,'v');
   if attrn(temp_dsid,'nobs')=0 then do;
      close_rc=close(temp_dsid);
      delete_rc=delete('newtable.'||memname);
  end;
end;
close_rc=close(lib_contents_dsid);
return;



Re: How to identify and delete empty datasets in an elegant manner

Postby shiling99 » Sun, 26 Mar 2006 04:48:52 GMT

You may modify the SQL below to achieve your needs.
HTH

1    data;
2    stop;
3    run;

NOTE: The data set WORK.DATA1 has 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.14 seconds
      cpu time            0.00 seconds


4    data;
5    stop;
6    run;

NOTE: The data set WORK.DATA2 has 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


7    data;
8    stop;
9    run;

NOTE: The data set WORK.DATA3 has 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


10
11   proc sql noprint;
12     select 'drop table '||compress(libname)||'.'||memname into:
dropstmt separated by ';'
13     from sashelp.vtable
14     where nobs=0 and memtype='DATA' and libname in ('WORK');
15     ;
16     &dropstmt
17     ;
NOTE: Table WORK.DATA1 has been dropped.
NOTE: Table WORK.DATA2 has been dropped.
NOTE: Table WORK.DATA3 has been dropped.
18   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.07 seconds
      cpu time            0.01 seconds


19
20   %put >>>"&dropstmt"<<<;







Re: How to identify and delete empty datasets in an elegant manner

Postby RandyHerbison » Sun, 26 Mar 2006 07:15:46 GMT

entry libname :input :char;

dcl num rc;

init:
dsid=open('sashelp.vtable(where=(libname=upcase("' || libname || '") and
nobs=0))');
any=attrn(dsid,'ANY');
if any then do;
  do until(fetch(dsid)^=0);
    rc=delete('work.'||getvarc(dsid,varnum(dsid,'MEMNAME')));
  end;
end;
dsid=close(dsid);
return;

-----Original Message-----
From:  XXXX@XXXXX.COM  [mailto: XXXX@XXXXX.COM ]
On Behalf Of  XXXX@XXXXX.COM 
Sent: Friday, March 24, 2006 2:45 PM
To: Jiann-Shiun Huang;  XXXX@XXXXX.COM 
Subject: Re: Re: How to identify and delete empty datasets in an elegant
manner


Or, you might consider the folllowing simple SAS Component Language
program.

length memname $32;
init:
  submit continue;
     proc contents data=newtable._all_ dir noprint out=lib_contents;
     run;
  endsubmit;
lib_contents_dsid=open('lib_contents','i');
do until(fetch(lib_contents_dsid)^=0);
   temp_dsid=open('sashelp.'||memname,'v');
   if attrn(temp_dsid,'nobs')=0 then do;
      close_rc=close(temp_dsid);
      delete_rc=delete('newtable.'||memname);
  end;
end;
close_rc=close(lib_contents_dsid);
return;



Re: How to identify and delete empty datasets in an elegant manner

Postby joewhitehurst » Sun, 26 Mar 2006 07:24:35 GMT

andy,

Nice work. I noticed that my solution would not have worked because I left out a call set statement, so values of memname on the contents dataset would never have been moved into the SCL nonwindow variable of the same name causing the delete function to fail.

Joe

Re: How to identify and delete empty datasets in an elegant manner

Postby Shelley.Baxter » Sun, 26 Mar 2006 11:44:15 GMT





Thank you for the help. I can see that the Shiling approach is the most
compact and elegant. I will keep the dictionary vs vtable distinction in
mind. I have thought about learning SCL since I won a book about it as a
door prize and keep finding myself in that documentation area and that's
the only way something can be done. But if I bunny trail off on that now I
will never get the project done!

Re: How to identify and delete empty datasets in an elegant manner

Postby BenDray » Tue, 28 Mar 2006 19:05:41 GMT

Hi Joe/Randy,

I like the look of the SCL program above - however I've never used SCL
and just tried to copy/paste into a SAS session but it's not working.
Can you tell me how to run this SCL code please??

Many thanks!!

Ben


Re: How to identify and delete empty datasets in an elegant manner

Postby joewhitehurst » Wed, 29 Mar 2006 02:29:47 GMT

Ben,

You must place the code in a SAS Catalog as member type SCL and compile it
before you can execute it.

Joe

-----Original Message-----
From: SAS(r) Discussion [mailto: XXXX@XXXXX.COM ] On Behalf Of BenDray
Sent: Monday, March 27, 2006 5:06 AM
To:  XXXX@XXXXX.COM 
Subject: Re: How to identify and delete empty datasets in an elegant manner

Hi Joe/Randy,

I like the look of the SCL program above - however I've never used SCL
and just tried to copy/paste into a SAS session but it's not working.
Can you tell me how to run this SCL code please??

Many thanks!!

Ben

Similar Threads:

1.How to identify and delete empty datasets in an elegant

2.FW: How to identify and delete empty datasets in an elegant

3.FW: How to identify and delete empty datasets in an

4.deleting empty files in a catalog

Hi,
I am planning to make a macro that has a catalog name as parameter and 
delete all empty files in that catalog.

%macro delete_empty_files(catalog);
???
%mend;

Has anyone made something like that before and can share it with me ? I am 
using Windows XP if it matters.

Regards, Rune




5.Deleting empty columns

I have datasets with 50+ variables. However not all of the columns are
being used. What would be the most efficient way to delete all columns
that are completely empty?

Thanks,
Gerrit

6. Why doesn't this macro delete the empty dataset?

7. identifying two different datasets

8. Identifying observations not in other Datasets



Return to sas

 

Who is online

Users browsing this forum: No registered users and 69 guest