DATA Step, Macro, Functions and more

Question about %input

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 131
Accepted Solution

Question about %input

Hi, I am learing the %input statement by running an example on the SAS's official  site: http://support.sas.com/kb/1/887.html

%macro test;

  %put enter the data:;

  %input getdata;

  %put The data you entered is: &getdata; run;

%mend test;

%test

However, this only resulted in an error: ERROR: Requested function is not supported.

I did follow the recommendation that: 'The workaround is to run the code within the SAS Program Editor rather than the SAS Enhanced Editor.'. But even so, the error still exists.

Do you know what's wrong with the %input statement?

Thanks a lot.


Accepted Solutions
Solution
‎01-30-2012 10:17 PM
SAS Employee
Posts: 104

Question about %input

You can enter the input data later by:
1.  Submit the macro definition code:

%macro test;                                                                                                                          

   %put enter the data:;                                                                                                              

    %input getdata;                                                                                                                   

    %put The data you entered is: &getdata;                                                                                           

run;                                                                                                                                  

%mend test; 

2. Submit the macro call:
%test

In the log you will see:

enter the data:

3. Type your data into the program editor window all by itself, and submit
abc123

In the log you will see the message:
The data you entered is abc123

It's kind of like getting user input with %WINDOW and %DISPLAY, without the windows... :-)

Not sure how practical it is, though.

View solution in original post


All Replies
Super User
Super User
Posts: 6,502

Question about %input

It will not work in a macro the same as the CARDS statement does not work in a macro.

PROC Star
Posts: 7,364

Question about %input

It will work if you are using the program editor, rather than the enhanced editor, but I think that the input has to be part of the submitted program code.  e.g., the following will work:

%macro test;                                                                                                                           

   %put enter the data:;                                                                                                               

    %input getdata;                                                                                                                    

    %put The data you entered is: &getdata;                                                                                            

run;                                                                                                                                   

%mend test;                                                                                                                            

                                                                                                                                       

%test                                                                                                                                  

xxxyyyzzz                                                                                                                              

However, I can't think of where that might be useful.

Respected Advisor
Posts: 3,777

Question about %input

What happens if you run the program from a command line?

Solution
‎01-30-2012 10:17 PM
SAS Employee
Posts: 104

Question about %input

You can enter the input data later by:
1.  Submit the macro definition code:

%macro test;                                                                                                                          

   %put enter the data:;                                                                                                              

    %input getdata;                                                                                                                   

    %put The data you entered is: &getdata;                                                                                           

run;                                                                                                                                  

%mend test; 

2. Submit the macro call:
%test

In the log you will see:

enter the data:

3. Type your data into the program editor window all by itself, and submit
abc123

In the log you will see the message:
The data you entered is abc123

It's kind of like getting user input with %WINDOW and %DISPLAY, without the windows... :-)

Not sure how practical it is, though.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 283 views
  • 3 likes
  • 5 in conversation