Macro variable in sas stored process - stored-procedures

I have a code in SAS.
proc sql;
create test as select * from test2 where user_name = &username;quit;
when I Run in SAS EG with %let username=Bob it runs normal.
But I need to run it with stored Process (variable username is internal parameter in connected user and I delete %let username=Bob from sas stored process code).
Stored Process brake with an error.
In log file I see variable:
_username=Bob but code in stored process can not find it. How to use this variable in SAS Stored process code? Thank you!

In your own SAS code, you use a macro variable username, but in your stored process, the user name is available in the reserved macro variable _username. The underscore is really part of the variable name, so you should write &_username.
For more information, you can read the documentation or you can consult the log after inserting
%put _automatic_;
in your code, to print all macro variables SAS provided for you.
Remark: As the automatic macro variables in a stored process differ from that in a local SAS session, if you want to use the same code in both, you often need some %if %then %else logic.

Related

Where does Postman store current value of environment variables?

I've been looking around my machine to see where the postman environment variables are stored. I've looked under AppData\Local\Postman, and C:\Users\username\Postman folders, and haven't found a config file that has a last modified date matching my change of environment variables.
I know I can export the environment variables, but I want to search over the current variables. And the exports don't include the current values, unless they replace the initial value, which I want to keep.
There are still ways to get around this. But I want to write a simple command to fetch some current environment variables via cmd, ex using grep.
So is there a way to check for the current environment variables? Where are they stored?
I don't think this will be a successful attempt. Postman seems to use a database, e.g. leveldb, according to information I found here. That will be stored as a binary file on your disk.
You can, however, have a look into the DB by going to View => Developer => Show DevTools and then going to Storage => IndexedDB => variable_sessions => workspace. I can find a current value for an environment variable like this:
But I don't see a way to search in this other than by keys which are uuids and not variable names or values.
All in all, exporting your environments into a text file might be the easiest option.

Detect environment variable change in Tcl

Is there any way to detect an environment variable change DURING the execution of a Tcl script (I use Tk so the execution can be long) ?
For instance, if I define an environment variable MYVAR=1, then I can access it from Tcl by writing $ENV(MYVAR). Let's say now that during the execution of the Tcl program, I switch MYVAR to 2. Is there a way, or maybe a command, that scans every environment variable again so I can get 2 when I call $ENV(MYVAR) ?
First off, other processes will not see changes to the environment variables of any process. Children get a copy of the current environment when they are created, and that's it.
Secondly, to see a change in the environment variables, put a trace on the ::env variable (but tracing an individual variable is not recommended). I can't remember if this works reliably between threads, but within a thread it's pretty good provided you don't have C code modifying the variables behind your back.
proc detectChange {name1 name2 op} {
# We know what name1 and op are in this case; I'll ignore them
if {$name2 eq "MYVAR"} {
puts "MYVAR changed to $::env(MYVAR)"
}
}
trace add variable ::env write detectChange
Note that Tk internally uses traces a lot (but the C API for them, not the Tcl language API for them).

Passing value to Cobol program through Parm using data in sequential file

I am setting up a JCL which will pass value of date coming from a sequential file (has one record) (example 20190320) to parm as shown below:
//STEP1 EXEC PGM=ABC,PARM='20190320'
I am trying to pass value of PARM with value of date containing inside sequential file.
Assuming that your COBOL program already contain instructions to retrieve the information passed from JCL using PARM, you may use the PARMDD parameter in conjunction with a DD statement to achieve the task. The DD statement is to define the sequential file with PARM data.
//STEP1 EXEC PGM=ABC,PARMDD=MYINPUT
//MYINPUT DD DISP=SHR,DSN=MY.PARM.INPUT
//SYSOUT DD SYSOUT=*
Dataset MY.PARM.INPUT can have the value of date.
Basically, you can't pass more than 100 bytes of data using PARM parameter. PARMDD is usually preferred if you want to pass data > 100 bytes.
Hope this helps.
You can not do this in the one job.
Options include
Changing the program ABC to read from the file
Writing a program/rexx to read the file and call the program ABC
Read the file and Generate a new job that calls ABC with the date you have just read. This could be done in a rexx script.
Some scheduling systems might support this.
Please provide a bit more information
What scheduling system does your company use
Is the program ABC a locally written program ??? that can be changed
Is the job part of a batch stream run automatically or submitted by a user.
Manual Submission
If the job is being submitted manually you could
Write a Rexx Script using ISPF file tailoring to generate && submit the JCL
Rexx Macro to update and submit the JCL
ISPF Edit macro
you could have
// set DATE=$Date$
//STEP1 EXEC PGM=ABC,PARM='&date'
in the jour JCL
and have the rexx edit macro
read the file
do a replace all on &date
I would use the same variables as Controlm
With JCL
// set DATE=$Date$
//STEP1 EXEC PGM=ABC,PARM='&date'
the edit macro would some thing like
/* rexx */
ADDRESS ISREDIT 'macro'
Address TSO "EXECIO 1 DISKR indd"
pull date
ADDRESS ISREDIT "r $date$" date
ADDRESS ISREDIT "cancel"
The edit macro needs to be in the SYSPROC or SYSEXEC libraries. If the
Macro is called ChgDate you would just

Is there any way in Netezza Stored Procedure to put output into file

Is there any way in Netezza Stored Procedure to put output into a file? By output I mean statements from Notice statement in Netezza. Also we can't use any shell or other script because the SP is being invoked via a tool which cannot execute shell scripts but only make DB calls.
There are multiple ways to write these values to a file -
1) Write UDX which can put your statements to disk
2) Every raise notice statement gets log in "/nz/kit/log/pg.log" file, so you need to write a bash which runs with cron or similar tool and extract required information for you.

Why is there a difference in memory address of environment variable when running a program

I write a C program gets in an environment variable's name and print out it's memory address, simply use the getenv() function to do the job. Let's say I wanna have the address location of PATH --> ./test PATH. But when I debug that program in gdb, the memory location of that variable is different. Can you explain in detail why is there such a different?
To be more exact:
./test PATH --> 0xbffffd96
debug in gdb --> 0xbffffd53
[edit] Thanks for your explanations. What I actually in question about is, how the memory address of a variable (in this case, an environment variable) changes with different programs. For example, I have 2 program a.out and b.out
./a.out --> PATH's address is some number
./b.out --> another number
So, what causes this difference between 2 numbers? I hope I have clearly demonstrated what I want to ask. Thanks mates.
Typically, environment variables are part of some "process data block", and those are inherited from the starting process. If you are running a program in a debugger, that debugger will have its own process data block and your program will inherit its process data block from the debugger. That in turn might have inherited the program data block of the IDE.
This doesn't matter anyway, because the interface to the environment variables doesn't give you that kind of details. For instance, on Windows it's quite likely that the environment variables will be converted from Unicode to your local 8 bit codepage when you ask for them. You'd never see the original variable, just (an approximation of) its value.
Perhaps you want to do?
printf("%s",getenv("PATH"));
Getting the environment variable string does make sense.
But, the address where the system gives you the string, has no relevance anywhere
(particularly outside the scope of this program).
You should be interested in the environment string value rather than its address.
If you have any reason to use the address, please give that here.
For example,
echo $PATH
gives me,
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin: ... etc
All my programmatic interest with PATH would be in its contents not any sort of address.
Why would you expect it to return the same memory location every time? getenv returns "a pointer to a string containing the value for the specified name." It is not specified which memory location the string is located at, nor whether that location will later be overwritten.

Resources