Transferring syntax to SAS EG and integrating prompts - sas

I've used this forum to gather information on creating and using prompts in SAS EG tasks and queries. However, I can't seem to transfer my own syntax from Base SAS, incorporate/reference prompts/macros I've created, and get it to work.
Currently, everytime I reference a prompt in my own program (rather than one generated by point-click selections in SAS EG) the log tells me SAS can't resolve the macro reference.
How can I transfer my own program into SAS EG and then integrate the prompts?
Example code I used to develop test data set:
data work.testscores;
input Gender $ 1-6 SATScore 8-11 IDNumber 13-20;
datalines;
Male 1170 61469897
Female 1090 33081197
Male 1240 68137597
Female 1490 9589297
Male 1200 93891897
Female 1080 26212897
Male 1050 8945097
Female 1200 51799397
Male 1600 39196697
;
run;
/created Genders prompt in the prompt manager using gender variable/
PROC SQL;
CREATE table WORK.testscores2 as
SELECT &Genders, SATScore
FROM WORK.TESTSCORES
;
QUIT;
Log:
102 PROC SQL;
103 CREATE TABLE WORK.TESTSCORES2 AS
104 SELECT &Genders
WARNING: Apparent symbolic reference GENDERS not resolved.
104 SELECT &Genders
_
22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, BTRIM, INPUT, PUT,
SUBSTRING, USER.
105 FROM WORK.TESTSCORES;
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
106 QUIT;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Thanks,A

Judging by the comments of the topic starter, it looks like there is some misunderstanding how prompts in EG work. It's not a tool for assigning value to some macrovariable BEFORE running your program. 'Prompt' implies that the program prompts you to enter the value DURING the program running. But for that, you have to assign your prompt to coressponding program, so that when you run this particular program SAS would envoke this particular prompt. For that: right click on the task -> Properties -> Prompts -> Add.

I dont understand what you want to achieve by your code. Do you want select just male or female SAT-scores based on the value of the macro variable you set in the prompt?
proc sql;
create table work.testscores2 as
select gender, satscore
from work.testscores
where gender = &genders.;
/* Where the value of &genders is either 'Male' or 'Female' */
quit;

To use a macro variable created in a prompt, you need to check the box "Use prompt value throughout project".

Related

Reading dates into sas from premade .dat dataset

Being asked to read in and format dates in a premade sas file. Question is as follows:
Read in BIRTHDATE and DEATHDATE to recognize them as dates. (Create new variables called birthdate2 and deathdate2 respectively).
So, i've created a copy of the dataset:
data presidents_datefix;
set myfolder.presidents1;
run;
And am trying to use the input function to read the birth and deathdates in:
data presidents_datefix;
infile "presidents1"
input Presidents $ 1-38 #2 Birthdate date9. Deathdate date9.;
run;
Before running this datastep, the presidents1_datefix viewtable loads just fine. After the datastep, I get a warning message that reads:
"WARNING: The data set WORK.PRESIDENTS_DATEFIX may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.PRESIDENTS_DATEFIX was not replaced because this step was stopped."
Then, when opening the viewtable, no observations exist anymore. I also get a series of error messages that say
ERROR 23-2: invalid option name
for every value of the input function.
Would really appreciate some help figuring out what I've done wrong and how I can fix it! Thank you!

Why doesn't my SAS Stored Process output the data set to E.G., while the log shows it's created?

I'm creating a stored process in SAS EG for some business partners, but I can't seem to get my dataset to output.
A 'Results' viewer shows up but is blank, and my code works perfectly fine when not using a stored process, but the user has to manually change the macro variable for the account they are looking for. With a stored process I can mitigate users accidentally deleting some code, etc.
I can see in my SAS log that the output dataset is being created with variables and observations, but it doesn't automatically pop up like a typical SAS EG job would. I also have some documentation I received from a co-worker around stored processes, and it seems to me that after successful execution a SAS dataset should automatically output.
One thought: Will a stored process output a dataset if there are warnings in the log? I have warnings presented because I am appending datasets to a base file that isn't created, so the lengths of my numeric variables change.
Here's a snippet from the log..
NOTE: The address space has used a maximum of 5504K below the line and 222716K above the line.
104
105 data tran_last;
106 retain TRAN_DT MRCH_NAME MRCH_CITY AMT_TRAN DEB_CRD_IND;
107 set tran_sorted;
108 output;
109 run;
The SAS System
NOTE: There were 164 observations read from the data set WORK.TRAN_SORTED.
NOTE: The data set WORK.TRAN_LAST has 164 observations and 5 variables.
NOTE: The DATA statement used 0.00 CPU seconds and 51817K.
NOTE: The address space has used a maximum of 5504K below the line and 222716K above the line.
The data set WORK.TRAN_LAST is the dataset I wish to be output so that my user can directly copy/paste from there, maybe I'm missing something apparent, but I can't seem to figure this out.
Version 7.1
The answer was extremely simple. I had to use
PROC PRINT DATA = MYDATA ;
RUN;
at the end of my stored procedure.
However, I have books from the SAS Institute that say you can retrieve an "Output Data" file from a stored procedure instead of the "Results Viewer" using proc print. This functionality must have been taken out with newer versions, or maybe I was doing something wrong.
To fix this issue, I have my SAS connected to an excel file that the end-user will run the program(s) from so that they won't need to worry about the output being "Results Viewer".

How is this SAS dataset being emptied?

Running SAS 9.3 supporting MXG 32.10 on Windows
I have a dataset, WORK.SMFLISTD, which has 15 obs. At the end of processing, it has 0 obs even though I can find no modification to it. I can find no reference to WORK.SMFLISTD between these two states. Searches for SMFLISTD in SASLOG find no reference to it. Searches for WORK find many DATASETS DELETE statements but none reference SMFLISTD. There is no overall DATASETS KILL for the WORK library. In any case, if there were, SMFLISTD still exists but with 0 obs. Given these conditions, how does this dataset end up empty?
Options are:
options source source2 symbolgen mprint;
At the beginning of the run:
77 data work.smflistd(keep=refdate dsname volser);
78 set
78 ! work.smflist(obs=&getcnt);
SYMBOLGEN: Macro variable GETCNT resolves to 15
79 run;
NOTE: There were 15 observations read from the data set WORK.SMFLIST.
NOTE: The data set WORK.SMFLISTD has 15 observations and 3 variables.
At the end of the run:
MPRINT(RUNCICSSMF): proc print data=work.smflistd;
MPRINT(RUNCICSSMF): title "SMFLISTD After";
NOTE: No observations in data set WORK.SMFLISTD.
MPRINT(RUNCICSSMF): data daily.smflist;
MPRINT(RUNCICSSMF): set work.smflistd;
MPRINT(RUNCICSSMF): modify daily.smflist key=dsnid;
MPRINT(RUNCICSSMF): procdt = datetime();
MPRINT(RUNCICSSMF): run;
3223 The SAS System 06:41 Wednesday, November 12, 2014
NOTE: There were 0 observations read from the data set WORK.SMFLISTD.
NOTE: The data set DAILY.SMFLIST has been updated. There were 0 observations rewritten, 0
observations added and 0 observations deleted.
There are a multitude of ways that this could be happening so searching for a reference to the table may not work.
You can run the code to the point where the table is created. Open the table (so that it is locked), and then finish running the rest of the code. Because the table is locked, the step that tries to empty it will fail and show in the log as either an ERROR: or a WARNING:.
As Robert says, there are many possibilities. One "gotcha" is the global obs setting:
options obs=0;
You could check for this..

Separate report pages when printed out-sas

I have a sas output, and for each person have some information. But each person is supposed to be on a separate page when printed out, in other words that PDF should be one page for each person. I didn't use macro in my code. Also I don't know how to make macro. So is there any way that I can separate pages without using macro?
Code:
data _null_;
set maingroup;
call execute('%bygroup(' || trim(maingroup) || ')');
run;
This code separate the people for each page. But I don't have macro, I changed the code little bit. Check the report as below.:
Ayda Ceyhan: 325
1258 458
Grade:3.0
Issues: Test
-------
Justin Costay: 526
1568 132
Grade:3.5
Issues: NA
This is the output, there are two people in here. I need them to separate for each page when print out.
This depends largely on your actual report; but in general, you should be able to use by groups rather than using macros.
A simple example:
ods pdf file="c:\temp\test.pdf" startpage=bygroup;
proc report data=sashelp.class nowd;
by name;
columns age sex height weight;
run;
ods pdf close;
The startpage=bygroup tells the PDF engine to print out a new page for each by group. You might need to use notsorted if your by variable cannot be sorted on. This may or may not exactly do what you want, depending on how you're producing the report.
If you're doing this with data step programming, you may have a harder time without having access to the macro that's doing it. I honestly wouldn't use data step programming; nowadays, proc report/tabulate/etc. are very good at producing reports in whatever format you want, and they're much more powerful than data step programming.
In your specific simple example, you may be able to issue ods pdf startpage=now; commands via call execute (and then use startpage=never on the original ods pdf statement).

Can I get some default/empty text to display if a PROC REPORT doesn't generate due to no valid data?

I have a SAS program that loops through certain sets of data and generates a bunch of reports to an ODS HTML destination.
Sometimes, due to small sets of data I run these reports for, a certain PROC REPORT will not generate because, for this set of data I'm on, there is no data to report. I get this message for those instances:
WARNING: A GROUP, ORDER, or ACROSS variable is missing on every observation.
What I want in the HTML is to display some sort of message for these like "did not generate" or something.
I tried to use return/error codes or the warning text above to detect this, but the error code is 0 (no problem, really?) and the warning text doesn't reset if the next PROC REPORT generates OK.
If it is of any importance, I'm using a data step with CALL EXECUTE to get all this PROC REPORT code generated for these sets of data.
Is there any way to generate this "did not generate" message or at least to catch these warnings per PROC REPORT?
You can substitute in a value for the missing observations in your report.
First redefine missing values to some character. I think you can only use a single character, I could be wrong, though.
options missing='M';run;
Then make sure to use the "missing" option in your PROC REPORT.
proc report data=somedata nowd headline missing;
....
run;
EDITS BASED ON COMMENTS
To get comments to show up, I see a few possibilities.
One, scan the the data set and check for missing values. If any are present throw a message out.
Data _Null_;
Set dataset;
file print notitles;
if obs = . then do;
put #01 'DID NOT COMPUTE';
stop;
end;
run;
Two, add a column with a compute:
define xx /computed "(Message)";
compute xx /char length=16 ;
if obs =. then xx = 'did not compute value in row';
Three, a conditional line using compute:
compute after obs;
if obs = . then do;
line #1 "DID NOT COMPUTE";
end;
endcomp;
endcomp;
See: http://www2.sas.com/proceedings/sugi26/p095-26.pdf
Look for the MTANYOBS macro and the section on printing a 'no observations' page.