Dynamic file creation thru SAS

sas

    Sponsored Links

    Next

  • 1. MSAccess Tables
    Hi all, Can we use MSAccess tables with SAS/AF through SCL with all the integrity constraints. My problem is that, i want to define ERD with relationships between tables but in SAS i'm not able to fine any tool where i can do that and since MSAccess has that feature that's why i wanna use Access tables directly in SAS. Thanx.
  • 2. WORK libname re-assigned
    Hi All, I experiencing some intermitent error related to the WORK library. It seems a though SAS is forgetting where the WORK library is suppposed to be located, and is instead using another location. This, of course, results in errors. Will LIBNAME ALL; let me trace through libname assignments/ unassignments? Thanks, Tim
  • 3. using format statement in proc summary
    Hi, I'm trying to use a format line (in my proc summary statement) that will convert my SAS date values to a calendar date. Although I think I have the informat right, for some reason SAS does not like the way I have set it up. I have reproduced it here if anyone has any thoughts. Thanks! Alex P.S. All values with the word "date" in them (such as date1 date2 etc) are in SAS date form prior to this proc summary step and I am trying to change only those variables into MMDDYY8. form and also to leave the other variable formats as they are.) proc summary data = lastfrontier missing nway noprint max; CLASS permno comnam ipodate; VAR date1 price1 shrout1 date2 price2 date7 price7 date14 price14 date30 price30 date60 price60 date90 price90 date180 price180 date365 price365 date730 price730; FORMAT date1 MMDDYY8. date2 MMDDYY8. date7 MMDDYY8. date14 MMDDYY8. date30 MMDDYY8. date60 MMDDYY8. date90 MMDDYY8. date180 MMDDYY8. date365 MMDDYY8. date730 MMDDYY8.; output out=summarystats max = d1 p1 s1 d2 p2 d7 p7 d14 p14 d30 p30 d60 p60 d90 p90 d180 p180 d365 p365 d730 p730; proc export data = summarystats outfile = 'summarystats.txt'; run;

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 17 guest