sas one-liner - sas

Is there a way to run a one-liner in sas, or do I have to create a file? I'm looking for something like the -e flag in perl.

My favourite is using the -stdio option
Either:
sas -stdio
Then start typing. Or ...
echo "proc options; run;" | sas -stdio

The Unix version of SAS was ported from MVS years ago and to make a long story short, the SAS executable does not import from STDIN. To make this work in Unix, merely alter slightly the previous suggestion into something like:
echo "your SAS code" > temp;sas -sysin temp
Hope this is helpful.

sas -initstmt '%put hello world ; endsas ;'
sas -initstmt 'proc print data=sashelp.class; run ;'
Off course this could also be:
sas -initstmt '%inc large_program.sas; endsas;'

Never having used sas, what I might try is something like:
echo <insert sas code here> | sas --execute-file -
Oftentimes applications will let you specify '-' as a file to have it read from STDIN. And 'echo' just prints its arguments out, and the | connects them together.

You could also use the -nodms option. This will give you a command line version of Base.

Related

How to set a shortcut instead of typing a part of the command 'youtube-dl -F'

I haven't used youtube-dl in a while and I do remember that I set 2 shortcuts:
one for "youtube-dl -F"
another one for "youtube-dl -f"
the shortcut is something simple like xx for 'youtube-dl -F' so that in the command line, I would just type xx [URL]
Now the thing is I dont know how I set it actually at that time and moreover I cant seem to remember what those shortcuts are (maybe they got deleted or so.. I am not sure)
Hoping someone can help me out on how to set them OR point me to a webpage where I can get those set of instructions.
someone in a different forum helped me figure it out.
I used 'aliases' in my zsh shell on iterm2.
Apparently I set 'sd' for "youtube-dl -F" & 'sdd' for "youtube-dl -f"

How to read the latest file in sas mainframes

I have a bunch of files like :
EESE.ABC123.ECIM.SAS.D160128,
EESE.ABC123.ECIM.SAS.D160202,
EESE.ABC123.ECIM.SAS.D160328,
EESE.ABC123.ECIM.SAS.D160502
I only want to read the latest created (D160502) file in mainframes using sas. Any help would be appreciated.
If you can use JCL then the following statement :
abc123 DD DSN=EESE.ABC123.ECIM.SAS(0), DISP=SHR
then in SAS use infile statement:
infile abc123 ;
it will take latest file. Hope this helps
** I don't know whether you are using JCL or not, so posted with JCL in case it might help you.

Parsing command output in Python

I'm trying to parse out from Popen. Output looks like a table:
SceenShotAttached
How do I print just the col c?
I could do it easily using awk in a shell script but I'm depending on python solely now.
Thank you!

How to replace using sed command in shell scripting to replace a string from a txt file present in one directory by another?

I am very new to shell scripting and trying to learn the "sed" command functionality.
I have a file called configurations.txt with some variables defined in it with some string values initialised to each of them.
I am trying to replace a string in a file (values.txt) which is present in some other directory by the values of the variables defined. The name of the file is values.txt.
Data present in configurations.txt:-
mem="cpu.memory=4G"
proc="cpu.processor=Intel"
Data present in the values.txt (present in /home/cpu/script):-
cpu.memory=1G
cpu.processor=Dell
I am trying to make a shell script called repl.sh and I dont have alot of code in it for now but here is what I got:-
#!/bin/bash
source /home/configurations.txt
sed <need some help here>
Expected output is after an appropriate regex applied, when I run script sh repl.sh, in my values.txt , It must have the following data present:-
cpu.memory=4G
cpu.processor=Intell
Originally which was 1G and Dell.
Would highly appreciate some quick help. Thanks
This question lacks some sort of abstract routine and looks like "help me do something concrete please". Thus it's very unlikely that anyone would provide a full solution for that problem.
What you should do try to split this task into number of small pieces.
1) Iterate over configuration.txt and get values from each line. To do that you need to get X and Y from a value="X=Y" string.
This regex could be helpful here - ([^=]+)=\"([^=]+)=([^=]+)\". It contains 3 matching groups separated by ". For example,
>> sed -r 's/([^=]+)=\"([^=]+)=([^=]+)\"/\1/' configurations.txt
mem
proc
>> sed -r 's/([^=]+)=\"([^=]+)=([^=]+)\"/\2/' configurations.txt
cpu.memory
cpu.processor
>> sed -r 's/([^=]+)=\"([^=]+)=([^=]+)\"/\3/' configurations.txt
4G
Intel
2) For each X and Y find X=Z in values.txt and substitute it with a X=Y.
For example, let's change cpu.memory value in values.txt with 4G:
>> X=cpu.memory; Y=4G; sed -r "s/(${X}=).*/\1${Y}/" values.txt
cpu.memory=4G
cpu.processor=Dell
Use -i flag to do changes in place.
Here is an awk based answer:
$ cat config.txt
cpu.memory=4G
cpu.processor=Intel
$ cat values.txt
cpu.memory=1G
cpu.processor=Dell
cpu.speed=4GHz
$ awk -F= 'FNR==NR{a[$1]=$2; next;}; {if($1 in a){$2=a[$1]}}1' OFS== config.txt values.txt
cpu.memory=4G
cpu.processor=Intel
cpu.speed=4GHz
Explanation: First read config.txt & save in memory. Then read values.txt. If a particular value was defined in config.txt, use the saved value from memory (config.txt).

Combining values from different files into one CSV file

I have a couple of files containing a value in each line.
EDIT :
I figured out the answer to this question while in the midst of writing the post and didn't realize I had posted it by mistake in its incomplete state.
I was trying to do:
paste -d ',' file1 file2 file 3 file 4 > file5.csv
and was getting a weird output. I later realized that was happening because some files had both a carriage return and a newline character at the end of the line while others had only the newline character. I got to always remember to pay attention to those things.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
file 1:
1
2
3
file2:
2
4
6
paste --delimiters=\; file1 file2
Will yield:
1;2
3;4
5;6
I have a feeling you haven't finished typing your question yet, but I'll give it a shot still. ;)
file1: file2: file3:
1 a A
2 b B
3 c C
~$ paste file{1,2,3} |sed 's/^\|$/"/g; s/\t/","/g'
"1","a","A"
"2","b","B"
"3","c","C"
Or,
~$ paste --delimiter , file{1,2,3}
1,a,A
2,b,B
3,c,C
you probably need to clarify or retag your question but as it stands the answer is below.
joining two files under Linux
cat filetwo >> fileone
Also don't forget about the ever versatile LogParser if you're on Windows.
It can run SQL-like queries against flat text files to perform all sorts of merge operations.
The previous answers using logparser or the commandline tools should work. If you want to do some more complicated operations to the records like filtering or joins, you could consider using an ETL Tool (Pentaho, Mapforce and Talend come to mind). These tools generally give you a graphical palette to define the relationships between data sources and any operations you want to perform on the rows.