2

Below is the script which I am using to execute the "read sub" but unfortunately not able to get the desired result.

#!/bin/sh

{
echo '%macro read;'

echo '%sysexec ( echo -n "Sub setting condition:");'
echo '%sysexec ( read sub) ;'
echo '%sysexec ( echo "Checking the macro [$sub]");'

echo '%mend;'

echo '%read;'
} > "/home/read.sas"
cd /home
sas /home/read.sas

Below is the result which I was expecting from above script:

Checking the macro [<text after entering the sub setting condition:>]

Thank you in advance for your help.

5
  • 1
    What is it you are trying to do? If you want to interact with SAS use the window or %window statements. Or possibly learn SCL programming. Commented Apr 3, 2018 at 13:21
  • Hi Tom, Thank you for your response. I am trying to write a shell script for sas program but in the above script "read" statement is not working properly it's having the value blank for "sub". Ideally it should have the value for "sub" once we are entering some string for the prompt of "Sub setting condition:" Commented Apr 3, 2018 at 18:59
  • Who is supposed to respond to the read command if it is being run in a command shell launched by a running SAS program? Commented Apr 4, 2018 at 0:35
  • When we run the shell script the SAS should run in batch mode and %sysexec function will execute the read command for unix. Commented Apr 4, 2018 at 4:57
  • Why? Why not execute the read in the shell script and use the data to generate the SAS code to run? That might actually work, where what you are trying to do is very tricky. If you really need to have SAS read from terminal then try using stdin is your infile. Commented Apr 4, 2018 at 12:35

3 Answers 3

1

Your output is probably saved in the sas log file.

See sample command below: specifying the file to execute and where to save the log file:

/sas/940/SASFoundation/9.4/sas /projects/program1.sas -log "/projects/program1.log" 
Sign up to request clarification or add additional context in comments.

Comments

1

Make sure that the .sas file you are executing is the SAS program not the file containing the macro function only.

Comments

1

You need to explain what you are trying to do. Your program might succeed in getting user input from the console, but the value will be stored in an environment variable that the SAS code cannot access.

You might be able to retrieve the value entered by writing it to a file and then reading from the file. But you need to make sure the read command and the command that references the environment variable read run in the same sub-shell.

So if I create this program as read.sas.

data _null_;
  call system ( 'echo -n "Sub setting condition:";read sub ; echo "Sub is $sub" >read.txt ' );
run;
data _null_;
  infile 'read.txt';
  input;
  put _infile_;
run;

And run it using sas read. Then the SAS log looks like this:

1          data _null_;
2            call system ( 'echo -n "Sub setting condition:";read sub ; echo "Su
b is $sub" >read.txt ' );
3          run;

NOTE: DATA statement used (Total process time):
      real time           2.80 seconds
      cpu time            0.02 seconds


4          data _null_;
5            infile 'read.txt';
6            input;
7            put _infile_;
8          run;

NOTE: The infile 'read.txt' is:
      Filename=.../test/read.txt,
      Owner Name=xxxx,Group Name=xxx,
      Access Permission=-rw-rw-r--,
      Last Modified=05Apr2018:08:45:02,
      File Size (bytes)=16

Sub is Hi there
NOTE: 1 record was read from the infile 'read.txt'.
      The minimum record length was 15.
      The maximum record length was 15.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.