Dynamic file creation thru SAS

sas

    Sponsored Links

    Next

  • 1. non-consecutive do loop
    hi all, I'm interested in doing a non-consecutive do loop, meaning I would like this code: do i = 1 to 12; ... end; do i = 21 to 32; ... end; to be a little more compact, to say something like this: do i = (1 to 12) and (21 to 32) ... end; any ideas ? Thanks
  • 2. Collapsing data into meaningful categories
    Hello, I'm new to the SAS world. please forgive my elementary question. I have data on customer home values (around 5000 obs). The values are listed as actual values. There is another column of frequencies. So there are something like 3500 unique values. I would like to collapse the actual home values into more tracteable categories while maintaining the frequencies for each category. The category breakdown would be something like: <50K 50-100k 150-200k 200-300k 300-500k 500-1,000k 1m+ Sample data value freq 102934 2 98328 1 400831 5 1039482 2 50000 3 If someone could point me in the right direction I would be grateful. Best, RON XXXX@XXXXX.COM
  • 3. calculate incidence of a disease
    Hi, I was wondering if anyone could help me with the sas code that i am working on to calculate incident patients in a healthcare dataset. I have 5 years of continous data (for ex 2000-2004) which has claims information. I would like to calculate incidence of a particular disease in paitents who would be present in the 01-04 years of the 5 year period. I am trying to figure out a code which would identify the first claim of patients from the years 01-04 and flag it as an index date, then the code needs to check if that flagged id had a claim in one year preceding the index date.The patients who dont have a claim would be the incidence of diseased population. Any help would be appreciated in this case. thanks sam

Dynamic file creation thru SAS

Postby Kannan » Sat, 21 Apr 2007 05:27:34 GMT

Hi All,
   We have SAS on mainframe.
I have situation where I need to dynamically create the file for each
unique Warehouse number. Below is the code I created to dynamically
allocate the files in mainframe.It is running fine for all the
situations except if there is out of space error. In other words the
file I am allocation has some default space limit if it exceeds that
limit my job getting failed.
My question:
   Is there any way I could increase/control the size of the output
file while creating the file dynamically. I have controlled the file
record length by using LS statement. I appreciate all your help.

Thanks!
Kannan.


Please find the below code:

Data Sas1;
Infile Whsefile;
Input @001 Whse    $char05.;
          @006 Items    $char100.;

Proc Sort;
By Whse;

data _null_;
set sas1 end=x; by Whse;
if _n_ = 1 then do;
   file print notitles;
   put / '               files created in this            ' /
         '              **************************        ' ;
end;

if first.whse then do;
   cnt+1;
   length fname $44.;
   fname=compress('myuid.whse.w'|| Whse||'.csv');
   link file_delete;
end;

file dummy filevar=fname mod recfm=fb Ls=105;
put @001 Whse $char05.;
      @006 Items $char100.

if x then do;
file print notitles;
put /
    'count of files generated : ' cnt;
end;
return;

file_delete:
rc1=0;
fn="tempfile";
rc=filename(fn,fname);
if rc = 0 and fexist(fn) then do;
       rc1=fdelete(fn);
       rc=filename(fn);
end;
if rc1  0 then do;
   put 'file deletion not successful';
   abort abend;
end;
return;


Re: Dynamic file creation thru SAS

Postby sbarry » Sat, 21 Apr 2007 06:01:40 GMT



Have a look at the SAS z/OS Companion Guide and the OPTIONS settings
for external file allocations, such as FILESPPRI= and FILESPSEC=, and
others.

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


Scott Barry
SBBWorks, Inc.


Re: Dynamic file creation thru SAS

Postby Kannan » Sat, 21 Apr 2007 23:04:53 GMT

n Apr 19, 5:01 pm, XXXX@XXXXX.COM wrote:

THANK YOU VERY MUCH Scott Barry. Now I am able to control the file
size by giving FILESPPRI= and FILESPSEC=. I have gave 100 for both by
overriding the default value of 1. Thanks again. It was a great help.

I need one more suggestion from you guys.
Right now, I am trying to delete the file if it exist by using the
statement fdelete(fn) where fn is the file reference. If the file is
being browsed by some other user then fdelete would return non-zero
value and hence I am abending the code.
Is there anyway I can stop the sas code for being run until the file
get released. This is something like giving DISP=SHR in JCL.
In more detail
I want to stop the execution of the sas process of a while until the
file get realsed. By this way I can re-allocate the file after the
file is released.

Reason is I am supposed to re-create the file with the same name. In
the meantime the same file might be used by some other process too.

Please send your suggestions.


Thanks!
Kannan.


Re: Dynamic file creation thru SAS

Postby sbarry » Sat, 21 Apr 2007 23:56:57 GMT

n Apr 20, 10:04 am, Kannan < XXXX@XXXXX.COM > wrote:

FDELETE does not provide a similar WAIT= which is used in the FILENAME
allocation technique (similar and would be my recommendation).
Unfortunately, you coding technique which uses the DATA step and
called function FDELETE, would need to be changed. The FILENAME
statement is not executed within a DATA step, but the allocation would
need to occur prior to the start of your DATA step, possibly through
your own "generated" SAS code (consider using CALL EXECUTE or use SAS
macro language), based on your SAS file content, as I understand your
logic. Here's an example of FILENAME as I use it frequently:

options errorabend;
%macro x(myfile);
%if %sysfunc(fileexist)) %then %do;
%* delete file if it exists - get OLD so we can delete it.;
filename del "&myfile" disp=(old,delete,keep) wait=60;
%* now clear the allocation which deletes the file. ;
filename del clear;
%end;
%* allocate the new file. ;
filename out "&myfile" disp=(new,catlg,delete).....;
%mend x;
%x(my.big.wooly.data);


Scott Barry
SBBWorks, Inc.


Re: Dynamic file creation thru SAS

Postby sbarry » Sun, 22 Apr 2007 00:23:13 GMT

n Apr 20, 10:56 am, XXXX@XXXXX.COM wrote:


Sorry, coding mistake - here it is again:

options errorabend;
%macro x(myfile);
%if %sysfunc(fileexist(&myfile)) %then %do;
%* delete file if it exists - get OLD so we can delete it.;
filename del "&myfile" disp=(old,delete,keep) wait=60;
%* now clear the allocation which deletes the file. ;
filename del clear;
%end;
%* allocate the new file. ;
filename out "&myfile" disp=(new,catlg,delete).....;
%mend x;
%x(my.big.wooly.data);


Re: Dynamic file creation thru SAS

Postby Kannan » Sun, 22 Apr 2007 01:11:17 GMT

n Apr 20, 11:23 am, XXXX@XXXXX.COM wrote:

THANK YOU THANK YOU THANK YOU!!!. It is working cool. I am able to
create the files without any problem. If file is used by some other
user , the wait option takinf care of it.
I have copied my sample code here. Please let me know if anything
needs to be changed or tweaked.
Thanks again Scott Barry.



Thanks!
Kannan.
OPTION MACROGEN NOCENTRE MISSING=0;

/*** Reading the input file ***/;
Data PRODFC;
Infile Whsefile;
Input @001 Whse $char05.;
@006 Items $char100.;


/**** Finding unique occurrences ***/;

PROC SORT DATA=PRODFC OUT=UNIFC NODUPKEYS;
BY Whse;


/*** Allocating the files ***/;

%MACRO ALLOCATE(FNAME);

%IF %SYSFUNC(FILEEXIST(&FNAME)) %THEN %DO;
%* DELETE FILE IF IT EXISTS - GET OLD SO WE CAN DELETE IT.;
FILENAME DEL "&FNAME" DISP=(OLD,DELETE,KEEP) WAIT=1;
FILENAME DEL CLEAR;
%END;

%* ALLOCATE THE NEW FILE. ;
FILENAME OUT "&FNAME" DISP=(NEW,CATLG,DELETE) RECFM=FB LRECL=105
SPACE=(CYL,(10,10),RLSE) UNIT=SYSDA;

%MEND ALLOCATE;

DATA _NULL_;
SET UNIFC END=X;

FNAME=COMPRESS('UID.WHSE.W'||Whse||'.TXT');
CALL EXECUTE('%ALLOCATE('||FNAME||')');

I+1;

CALL SYMPUT(COMPRESS('FNAME'||I),FNAME);
CALL SYMPUT(COMPRESS('Whse'||I),Whse);

IF X THEN
CALL SYMPUT('NOOFFILE',I);

RUN;


/*** Writing the file ***/;
%MACRO READ;
%DO I = 1 %TO &NOOFFILE;
DATA _NULL_;
SET PRODFC;
IF Whse="&&Whse&I";
FILE "&&FNAME&I";
PUT @001 Whse $CHAR05.
@006 Items $CHAR100.
;
%END;
%MEND READ;

%READ;


Similar Threads:

1.Rgdng Reading Data from External file & thru cards....

Hi all;

  Can anyone of you please make me understand the concepts of column
pointer,why it is giving two different outputs when the same data is read
from cards and thru an external file....

  My program is like this...

  Data test;
  Input name $ 1-4 age 7-8 id 10-11;
  cards;
  Ruth 45 54
  mahi 68 68
  Sue 45 36
  John 14 25
  ;

 when i run the above program:
 O/P  for 3rd obs SUE is like 3 .

 the same data when stored in external file:with this program
the data is stored in same way in external file as issued through cards,but
still the output varies why..please make me understand...
 data test1;
  infile 'C:\Documents and Settings\admin\Desktop\Applicatation\asd.txt';
  Input name $ 1-4 age 7-8 id 10-11;
  run;

  O/P is :

 Ruth 5 .
 sue 3 .

2.Automated import of dynamic labeled files into SAS

Hi,

I want to write a SAS-Base program which is able to import dynamic
labeled files into SAS. The filenames have no specific pattern. Only
one part of the filename is static. For example:
File 1: attach_first.txt
File 2: attach_hour.txt
...
File 1000: attach_town.txt

The structure of the file content is in every file the same.

Exist in SAS wildcards to read in these Files?

I would be happy to get a solution!

A lot of Greetings from Germany.

Tom

A normal SAS-program with proc import looks like:
proc import datafile="D:\Service\Research\attach_first.txt"
            out=work.attach_first
	    dbms=dlm
            replace;
            delimiter='|';
	    getnames=yes;
run;

3.Dynamic allocation of output files in a SAS program

Hi,
Is it possible to dynamically allocate output files in a SAS program.
I guess it is possible in Assembler.

4.How to get the location of SAS code in the same SAS code thru

Hard to say what you mean with that!
I start a interactive SAS session in Windows, then I include a SAS-program
from "p:\myfiles\test.sas". In that program you want to know, that I
included it from 'p:\myfiles\'? That is impossible! What are YOU doing?
Perhaps you have a batch program on a mainframe which %INCLUDEs a source
from a known location and does... The situation is somehow different then.

You see, without knowing what you are doing, where you are and what you
WANT to do, there is no chance to get it.

Gerhard




On Wed, 11 Apr 2007 07:43:50 -0700, Alok < XXXX@XXXXX.COM > wrote:

>Hi all,
>
>I am facing a problem in which I need to get the location/path of a
>SAS code in a macro variable. I need to use the macro variable in the
>same SAS code. Is there any SAS option available which can do this for
>me? Or is there a code snippet which can achieve the same purpose?
>
>Can you please help me out as soon as possible since I need to deliver
>this tomorrow. Any help will be greatly appreciated.
>
>
>Thanks,
>Alok

5.file creation date

It's so rare I can offer help rather than seek advice from others -

Nina, you can do a proc contents on a file and keep the output.  One field
that will stored is called CRDATE.  That should give you what you need.

e.g.,

proc contents noprint data=myfile out=temp;

data temp; set temp; if _n_ eq 1;

proc print; var crdate;

HTH-

Deb

6. Reading in a flat file with dynamic headers

7. Dynamic sequential file allocation on MVS

8. Sending e-mail thru SAS



Return to sas

 

Who is online

Users browsing this forum: No registered users and 70 guest