Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substr Function (SAS) 2

Status
Not open for further replies.

BobinSC

Programmer
Jun 5, 2007
5
US
See attached: %LET TIMENOW=%SYSFUNC(SUBSTR(TIME(),1,5));

I am getting error message in trying when running this
code. States it is missing open or closed (. Can any offer assistance.

 
First off this statement would throw a nasty warning even in Base SAS. SAS has a time format that will display only the hour and minutes. Why not use that format? Also, you may need to use the SYSFUNC macro feature a few times to get the desired results in MACRO.


In base SAS you would do the following:
Code:
data _null_;
  x = put(time(),time5.);
  put x=;
run;

In MACRO you would do the following:
Code:
   %LET TIMENOW=%SYSFUNC(putn(%sysfunc(time()),time5.));

Hope this helps you.
Klaz
 
I am getting the following error :

45
46 FILENAME OUTHTML
47 "TEST.MEMB.REQ53.NAOPINF.D&DATENOW.D&TIMENOW..HTML"
WARNING: Apparent symbolic reference SASTMP1 not resolved.
48 DISP=(NEW,CATLG,DELETE)
49 UNIT=SYSDA
50 SPACE=(CYL,(50,50),RLSE)
51 LRECL=300 BLKSIZE=0;
ERROR: Invalid file, TEST.MEMB.REQ53.NAOPINF.D17322DTIME( .
+ERROR: Invalid file, TEST.MEMB.REQ53.NAOPINF.D17322DTIME( .
+ERROR: Invalid file, TEST.MEMB.REQ53.NAOPINF.D17322DTIME( .
ERROR: Error in the FILENAME statement.

Please note I an just learning SAS. I am attempting to name my output file each time I run it with a differnt name to avoid errors.

Thank you so much for your help.
 
You want to name the file? Why didn't you state that earlier. You can't name a file with the ':' character. (At least in windows. Also you need the '.' char to let the SAS macro compiler know that it is dealing with a macro variable.
Try this:
Code:
%LET TIMENOW=%sysfunc(compress(%SYSFUNC(putn(%sysfunc(time()),time5.)),':'));

You can always check the way the macro variable has resolved by setting the symbogen in the options.

ex, at the top of your program:
Code:
options macrogen symbolgen;

I hope that this helps you.
Klaz


 
Kltaz

I am a retired licensed accountant who is now working
at another job. I have good wxperiance in running DB2 QMF queries.

I have now been transfered to another department and haave been assigned the task of learning SAS on my own, from existing jobs and from books. It is a killer task.

Your help is really appreciated. Do you know of a telephone subscription service for SAS (I'm using a mainframe version)? I'll let you know how it goes. All I am trying to do is to get a unique file name every time I run a job. Tnaks again.
 
Telephone subscription service? SAS has technical support for each valid licensed location. You can call sas @ tech support and give them your SAS site ID and they will help you with whatever sas question you need answered.

That said, here is how I generate unique file names (in windows, but you could tweak it for the mainframe).

ex
Code:
 %let DateStamp   = %sysfunc(putn(%sysfunc(date()),yymmdd10.))_%sysfunc(compress(%sysfunc(putn(%sysfunc(time()),time8.)),:));
 %let OutFileName = C:\CLIENTS\Myfolder\DailyReport.&DateStamp..pdf;

The DateStamp macro variable resolves to 2007-06-05_172005.pdf. In other words, today's date + the time as of 5:20pm and 5 seconds. You can use the same concept on the Mainframe and create your file name the same way.

I use this in the program as follows:
Code:
filename Myout "&OutFileName";

data temp;
  set mydata;
  file Myout;
  *** more datasteps **;
run;

I hope that you successfully teach yourself SAS. It is very rewarding. If you have any questions feel free to ask away.
Klaz
 
Klaz

I am having issues with the naming convention and main frame limitation. The nodes must start with a letter and are limited to 8 characters. Programers here also limit file names to 4 node. It may allow more.
 
Klaz, I hope you don't mind my jumping in on this thread. I use SAS on the mainframe, so I know what kind of a pain it can be.

BobinSC,

Since your goal is to create unique filenames, you might try the technique I found fro the SAS Institute: Creating a File with a Unique Name.

Their technique uses the random function to create a seven-digit random number that's prepended with a character.

Hopefully you'll find this works for you.

As an aside...

In your query's where clause, you have the following:
[tt]AND INQ_STATUS_TYPE NOT IN ('CL')[/tt]

Rather than using a NOT IN clause, you could use the not equals clause:
[tt]AND INQ_STATUS_TYPE ^= ('CL')[/tt]
The "^" is Shift+6, which most likely will appear as "¬" and simply means "not". Either way works, just thought I'd offer an alternative.

- Larry


 
Larry,

I am aso new to forums..and I hope it is ok add admin or thank you comments... as a thread.

I appreciate your help and will give it a try.
 
It's actually a good thing to add comments and thanks. It lets the poster know when their suggestion works. It's also good for those in the future who read this thread to know what works.

Thanks too for the star. And welcome to the forum.

- Larry
 
G'day, just going to add my 2 cents worth.
As an alternative to "^=" you can also use "NE" or "ne" (it's not case sensitive) for Not Equals. It avoids any character translation issues you may experience. From my - admittedly dim - memories of using SAS on the mainframe, I had some issues with transferring code from my PC to the Mainframe and back with special characters being translated incorrectly.

You also have available
GE for >=
LE for <=

Also, if you're struggling to pick up SAS by yourself, I've been told that "The Little SAS Book" is an extremely good book for beginners, especially if you can't persuade your employer to send you on the SAS Basics course. If you can persuade them, the PROG1 course is supposed to be a pretty good course, and you generally get a free copy of the book during the course.

And obviously, we're all wonderful, helpful people here too. :)


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top