Dynamic file creation thru SAS

sas

    Sponsored Links

    Next

  • 1. Compressing long fields
    I imported some Excel files containing fields of unknown length. So I read every field as a 100-character string. Now I'd like to compress each field down to its smallest possible length. So if the longest string in a field is 10 characters, then the field length can be $10. I want to do this in an automated fashion, so I don't have to explicitly look at the length of every field. Any tips? Thanks, Paul
  • 2. OT: Friday Night Humor
    I totally agree with Paul that the list seems to need some additional humor this week. I parsed all of the individual words which appeared on last year's posts. Of course, I manually excluded the To:, from: reply-to:, a, the, and, etc. variety but, what remained, I thought you might enjoy. In short, what word/strings/names do most of us type (or allow our computers to type for us) most often? I left posting days in, as it shows which days we all spend most time here. Enjoy, Art Rank word Frequency 1 MACRO 16029 2 DAVID 9560 3 MORE 9421 4 SQL 7224 5 THANKS 6714 6 "TUE," 6579 7 "WED," 6471 8 8BIT 6205 9 "THU," 6158 10 FORMAT 6126 11 THINK 6078 12 SELECT 5989 13 READ 5978 14 %LET 5951 15 PROBLEM 5918 16 "FRI," 5917 17 MODEL 5825 18 I'M 5548 19 PLEASE 5496 20 "MON," 5471 21 TOBY 4987 22 CASSELL 4771 23 ODS 4533 24 DUNN 4504 25 GROUP 4493 26 INFORMATION 4482 27 SOMETHING 4475 28 OBSERVATIONS 4372 29 ERROR 4258 30 MIGHT 4247 31 WERE 4246 32 QUESTION 4237 33 BECAUSE 4233 34 GOOGLE 4227 35 GOOD 4199 36 HI 4189 37 EXCEL 4111 38 PM 4098 39 LIST 3989 40 THEM 3978 41 NOW 3964 42 WHY 3953 43 AFTER 3895 44 ELSE 3842 45 FUNCTION 3816 46 ANYONE 3780 47 MUCH 3753 48 ARRAY 3750 49 SECONDS 3725 50 C 3712

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