conditional %include script sas - include

I tried to run conditional sas script based on the macro variable &syshostname.
data name;
name = "&syshostname.";
run;
data _null_;
set name;
if name = 'abc' then
do;
call symput('rrun','script1.sas');
end;
else
do;
call symput('rrun','script2.sas');
end;
run;
%include &rrun.;
Error Message: WARNING: Physical file does not exist, C:\Program Files\SASHome\SASFoundation\9.3\&rrun..
How can i direct it use the path &runn.. but not with those C:\Program Files XXXX ?

If you dont provide a path for your files, a specific default path will be choosen.
So where are your files script1.sas and script2.sas located?
You must add the path to the location of the files in the macrovariable, e.G.:
call symput('rrun','D:\mySasFiles\scripts\script1.sas');
also, when including the files, you must provide the path as string, so you need to add ""
%include "&rrun";
Another option would be to save your script files in the default path location, but anyway, you need to add the "".

Related

code to list the content of zipped text files in cmd or SAS ?

code to list the content of zipped text files in cmd or SAS ? There are so many answer, but no one exactly pointing to this question. Without downloading any other .exe or installing package file. Please help thanks.
A zip file is an aggregate storage location, much like a regular folder is. The statement INFILE aggregate-fileref FILENAME= option will deliver the current aggregrate items name. However, it appears the ZIP filename engine does not honor this convention. Regardless, you can still access all the contents of each file in the zip.
Create a zip file with two members:
filename archive ZIP "%sysfunc(pathname(WORK))\testzip.zip";
%put NOTE: Archive file is %sysfunc(pathname(archive));
%put NOTE: Delete archive, rc=%sysfunc(fdelete(archive));
data _null_;
file archive(one.txt);
put 'i'; do i = 1 to 10; put i; end;
data _null_;
file archive(two.txt);
put 'z'; do z = 10 to 20; put z; end;
run;
Create two text files in a regular folder (they will be used to contrast aggregate input from ZIP and OS folder):
filename folder "%sysfunc(pathname(WORK))";
data _null_;
file folder(one.txt);
put 'i'; do i = 1 to 10; put i; end;
data _null_;
file folder(two.txt);
put 'z'; do z = 10 to 20; put z; end;
run;
Read from multiple files in the regular folder using aggregate syntax. Notice how the filename is logged:
data _null_;
length filename $250;
infile folder(*.txt) filename=filename; * specify which aggregate members to process;
input;
if filename ne lag(filename) then put 'NOTE: ' filename=;
put _infile_;
run;
----- LOG -----
NOTE: filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD24468_HELIUM_\one.txt
i
1
2
...
NOTE: filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD24468_HELIUM_\two.txt
z
10
11
Now read from zip as an aggregate. Unfortunately the filename value does not change when the ZIP engine moves to the next member in the zip. Regardless, you still get the contents:
data _null_;
length filename $250;
infile archive(*.txt) filename=filename;
input;
if filename ne lag(filename) then put 'NOTE: ' filename=;
put _infile_;
run;
----- LOG -----
NOTE: filename=C:\Users\Richard\AppData\Local\Temp\SAS Temporary Files\_TD24468_HELIUM_\testzip.zip
i
1
...
10
z
10
...
20
NOTE: A total of 23 records were read from the infile library ARCHIVE.
If you need to get a list of the member names in the zip file, in Windows, with no other installation there are powershell solutions, and within SAS you can also perform Proc GROOVY to run java code that processes a zip file. In a locked down server environment both of these approaches would not be available as they are deemed external agents that pose a security risk or unmonitored server resource use.

Pass Path Parameter to a Exe File in a batch File

I want to pass the path parameter to the exe file:
TableUpdate.exe "C:\Documents"
In my batch File i written as :
#set Fpath = "C:\Documents"
#TableUpdate.exe %Fpath%
but when i enter the the path directly that exe file is able to recognize the execute but when i pass the path as parameter but it is not able to recognize the path passed. How to pass the path as parameter to exe file in a batch file.
set Fpath = "C:\Documents"
Remove the spaces on both sides of the equals sign as they are included in the variable name and the variable contents.
This is one way to specify it.
set Fpath="C:\Documents"
The # is ok, but not needed when you have #echo off at the start.

What is common practice for the location of temporary files after Windows XP [duplicate]

Currently I am using following function to get the temporary folder path for current user:
string tempPath = System.IO.Path.GetTempPath();
On some machines it gives me temp folder path of current user like:
C:\Documents and Settings\administrator\Local Settings\Temp\
On some machines it gives me system temp folder path like:
C:\Windows\TEMP
MSDN Documentation also says that above API returns current system's temporary folder.
Is there any other API available which gives me current user's temporary folder path like this:
C:\Documents and Settings\administrator\Local Settings\Temp\
System.IO.Path.GetTempPath() is just a wrapper for a native call to GetTempPath(..) in Kernel32.
Have a look at http://msdn.microsoft.com/en-us/library/aa364992(VS.85).aspx
Copied from that page:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
It's not entirely clear to me whether "The Windows directory" means the temp directory under windows or the windows directory itself. Dumping temp files in the windows directory itself sounds like an undesirable case, but who knows.
So combining that page with your post I would guess that either one of the TMP, TEMP or USERPROFILE variables for your Administrator user points to the windows path, or else they're not set and it's taking a fallback to the windows temp path.
DO NOT use this:
System.Environment.GetEnvironmentVariable("TEMP")
Environment variables can be overridden, so the TEMP variable is not necessarily the directory.
The correct way is to use System.IO.Path.GetTempPath() as in the accepted answer.
I have this same requirement - we want to put logs in a specific root directory that should exist within the environment.
public static readonly string DefaultLogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
If I want to combine this with a sub-directory, I should be able to use Path.Combine( ... ).
The GetFolderPath method has an overload for special folder options which allows you to control whether the specified path be created or simply verified.

Using MakeCab.exe & .ddf file (i.e. using directive file) how to specify destination cab filename?

I have decided to use makecab.exe for my requirement to create cab files in my application.
http://msdn.microsoft.com/en-us/library/bb417343.aspx#microsoftmakecabusersguide
And I need to store files as per given path whether relative or absolute inside cab and extract files with original path preserved. So I will be using directive file for this and give that input to makecab command.
windows command promt zip/compress directory
But the cab output is stored in folder Disk1\1.cab.
Please help me to know how can I specify a desired cab filename as destination (I will take cab file name from user input)?
Also, is it possible to append more files to existing cab file in second run of makecab command?
Finally found the solution.
You can set following two variables in the directive file which will identify destination path and name of cab file:
DiskDirectoryTemplate=template [Output directory name template; * is replaced by disk number]
CabinetNameTemplate=template [Cabinet file name template; * is replaced by Cabinet number]
Description from Microsoft MakeCAB User's Guide
DiskDirectoryTemplate=template
Set the output directory name template. One directory is created for
each disk of the layout.
Default: .Set DiskDirectoryTemplate=DISK* ; Default is DISK1, DISK2,
etc.
As MakeCAB processes a directive file, it will create one or more
disk "images". Rather than using some specific disk format, however,
MakeCAB simply creates one subdirectory for each disk and places the
files for each disk in the appropriate directory. If a * exists in
this variable, then it is replaced with the disk number. If no * is
specified, then all files are placed in the single directory specified
by this variable.
This variable is used only if no variable DiskDirectoryn exists for
disk n.
Examples:
.Set DiskDirectoryTemplate=C:\EXCEL6\DISK* ; Put files in separate dirs
.Set DiskDirectoryTemplate=C:\EXCEL6 ; Put all files in C:\EXCEL6
.Set DiskDirectoryTemplate= ; Put all files in current dir
CabinetNameTemplate=template
Sets the cabinet file name template.
Default: .Set CabinetNameTemplate=*.CAB ; 1.CAB, 2.CAB, ...
This template is used to construct the file name of each cabinet. The *
in this template is replaced by the cabinet number (1, 2, etc.). This
variable is used only if no variable CabinetNamen exists for cabinet
n.
NOTE: Be sure that the expanded cabinet name does not exceed the
limits for your file system! For example, if you used "CABINET*.CAB",
and MakeCAB had to create 10 or more cabinets, then you would have
cabinet names like CABINET10.CAB, which is 9.3, which is an invalid
name in the FAT file system. Unfortunately, MakeCAB would not detect
this until it had already created 9 cabinets!
Examples:
.Set CabinetNameTemplate=EXCEL*.DIA ; EXCEL1.DIA, EXCEL2.DIA, etc.
.Set CabinetNameTemplate=*. ; 1, 2, 3, etc.
In addition, when files are split across cab (in case if cabinet size exceeds its limit size) then you can set subsequent cabinet filenames also using variable CabinetNamen:
CabinetNamen=filename [Cabinet file name for cabinet number n]
CabinetNamen=filename
The cabinet file name for the specified cabinet.
Default: ; By default none of these variables are defined
If this
variable is not defined for a particular disk, then MakeCAB uses the
CabinetNameTemplate to construct the cabinet name.
Example:
.Set CabinetName2=test2.cab
If you know exactly where your source files exist, you can generate a file list from the directory:
dir C:\FolderName /s /b /a-d > c:\temp\files.txt
Then use the files.txt file to create the cab file.
makecab /d CabinetName1=test.cab /D DiskDirectoryTemplate=C:\temp /f c:\temp\files.txt
The above command will generate a test.cab file in your C:\Temp folder using the file list generated earlier.
Additional helpful reference:
Microsoft Cabinet Reference. and
makecab.exe details.

How do I specify a relative local file path in DOS? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I dynamically specify a file in DOS?
I am using c#.NET 2.0 to execute DOS commands to ftp a file. All works except for 1 thing, in the cmd file I call, it runs a PUT statement. Right now the put statement has a hardcoded local file path. I need to specify a dynamic path. I've tried
put %~dp0\myfile.DTL myfile.dtl
but it says it can't find the file.
Right now the .NET code calls a BAT file which only exist to call the CMD file. Interestingly, the BAT file DOES successfully use a relative path in its call to the CMD file:
ftp.exe -s:%~dp0\oit.cmd
However, I can't get that relative path to wrok in the cmd file:
open <my host>
<user name>
<password>
put <hardcoded path that needs to be relative path>localfilename remotefilename
I'll bever know where it will exist so I just need to grab whatever local directorey the file is in.
Relative is "." (dot).
Can you post the exact situation? What directory are you in, and where is the file?
Be careful with the "~" char ... it has a special meaning for DOS files (8.3 notation)
Use System.IO.Directory.GetCurrentDirectory() to get the current (working) folder.
Alternatively, if you want the path relative to your .EXE file, you can use System.Reflection.Assembly.GetEntryAssembly().CodeBase to get full path to your .EXE file, then use System.IO.Path.GetDirectoryName() to get the directory name of that path.
After that, you can use System.IO.Path.Combine to get absolute path out of relative:
string absPath = Path.Combine( #"c:\working\folder", #"sub\folder\file.ext" );
// absPath == "c:\working\folder\sub\folder\file.ext
// Works with double-dot too:
string absPath2 = Path.Combine( #"c:\working\folder", #"..\up\file.ext" );
// absPath == "c:\working\up\file.ext

Resources