This is my first time using a programming related stack. So if this doesn't belong or should go somewhere please inform me and I will fix it.
I've just begun to use SAS Studio. I believe I have set up a title correctly, but I can't seem to get it only on the first page. It adds the title to every subsequent page I create. I've just begun watching tutorials on the SAS website, but I have yet to run across the answer to this particular question. Can anyone help point me in a correct direction?
Here is my code:
Data Question21;
Input Transfers Broken ##;
Datalines;
1 16 0 9 2 17 0 12 3 22 1 13 0 8 1 15 2 19 0 11
;
title color=red Bold underlin=3 "Assignment #1";
Proc Print;
run;
Proc sgplot;
scatter x=Transfers y=Broken;
run;
Proc reg;
model Broken=Transfers;
run;
and this is a sample of what happens when it runs:
TITLE is a global statement, and will take effect until you turn it off. So the simple answer is: after the PROC in which you want the title, and its RUN statement (or QUIT in those that use quit), enter
title;
Which will then clear all titles.
In a bit more detail:
Titles, and Footnotes, have a set of ten (each) that are in a sort of 'stack' (Setting one removes all higher ones). SAS stores them internally, and any time a PROC or anything else runs that supports a title, it will grab whatever is currently in the title and footnote stacks and show those titles and those footnotes.
It is important to remember that any PROC or DATA step doesn't submit fully until RUN or QUIT is reached, or else another PROC or DATA step is begun (called a "Step Boundary"). Since TITLE is a global statement, what'll happen is whatever is in the current title stack when the step boundary is reached will be shown. Notice what you actually see here...
title "One Title";
proc print data=sashelp.class;
title "Two Title";
run;
title "Three Title";
proc freq data=sashelp.class;
tables sex*age/list;
run;
title "Four";
A good habit is to always put TITLE statements in a consistent place - some disagree over where, but choose either:
Before the PROC/DATA statement
Immediately before RUN
and stick with it. Then, after every RUN, include a TITLE;, unless you intentionally have a common title.
For example, I might have an assignment that is to print SASHELP.CLASS, run some frequencies on it, and use PROC UNIVARIATE to look at the WEIGHT and HEIGHT variables.
title "SAS Class, Assignment One";
title2 "Written By Joe, 9/2/2015"; *these are global titles used for all printing;
title3 "Print of first 10 obs of SASHELP.CLASS";
proc print data=sashelp.class(obs=10);
run;
title3;
title3 "Freq of AGE, SEX in SASHELP.CLASS";
proc freq data=sashelp.class;
tables age sex;
run;
title3;
title3 "Univariate Examination of SASHELP.CLASS";
title4 "HEIGHT variable";
proc univariate data=sashelp.class;
var height;
run;
title4;
title4 "WEIGHT variable";
proc univariate data=sashelp.class;
var weight;
run;
title3; *notice 3 here - ending all of 3;
title3 "Plot of SASHELP.CLASS Height v Weight";
proc sgplot data=sashelp.class;
scatter x=weight y=height;
run;
title; *ends all titles!;
Related
I'm an Animal science student from Slovenia and I'm just finishing my master's thesis. For the finishing touches i need to make a bunch of scatter plots of different traits. All my data values (breeding values of different traits) are in code, for example m_pv10 (omišičenost = muscularity), m_pv31 (age of first calving),... To make the scatter plots easier to read i'd like to rename the x and y-axis labels from m_pv31 to "Age of first calving". I have tried renaming the values in a data step to bypass this problem but some names of the traits include spaces "age of first calving" and no nregular letters as "š" and "č" so the data step won't work.
data datam_copy;
set datam_copy;
rename m_pv10=Omišičenost;
m_pv31=Starost ob prvi telitvi;
m_pv12=Vime;run;
Is there a way to rename the axis labels directly in the sgplot code?
I would be very tratefull for any suggestions.
Urban
You can use the variable label, if that is the level you're working at. Here's an example.
data have;
set sashelp.class;
label age="Age of student"
height="Height of student"
weight="Weight of student"
;
run;
proc sgplot data=have;
vline age/response=height;
vline age/response=weight y2axis;
run;
You can rename the variable also of course, but this is really the job of the variable label. You can also use the label statement directly in sgplot.
proc sgplot data=sashelp.class;
vline age/response=height;
vline age/response=weight y2axis;
label age="Age of student"
height="Height of student"
weight="Weight of student"
;
run;
You can have spaces in the name but generally not a great idea though.
Not sure how the accents will work though.
options validvarname = any;
data datam_copy;
set datam_copy;
rename m_pv10= 'Omišičenost'n;
m_pv31= 'Starost ob prvi telitvi'n;
m_pv12= 'Vime'n;
run;
Hi I am trying to make two tables that are sorted I believe with proc means or at least the first one I was able to make with proc means. I created the first table with this code.
proc means data=onetable mean noprint;
var Score;
class Form QuestionNumber;
ways 2;
output out=table (drop=_TYPE_ _FREQ_) mean=QuestionPercentage;
run;
title "Section B: Question Analysis "
"Sorted by Exam Form and Question Number";
proc print data=table noobs;
format QuestionPercentage percent8.1;
run;
Which produces a table that looks like this
Form
QuestionNumber
QuestionPercentage
A
1
16.0%
A
2
76.0%
A
3
42.0%
Now I am trying to make the second table that looks like this
Form
QuestionNumber
QuestionPercentage
A
9
100.0%
A
39
100.0%
A
101
100.0%
which I think should be made with proc means but I get the error QuestionPercentage not found. I think it might have to do with the mean=QuestionPercentage or what table I am using. Here is my code for the second table.
proc means data=onetable mean;
var Score;
class QuestionPercentage;
ways 2;
output out=table1 (drop=_TYPE_ _FREQ_) mean=QuestionPercentage;
run;
title "Section B: Question Analysis "
"Sorted by Question Percentage";
proc print data=table1 noobs;
by descending QuestionPercentage;
format QuestionPercentage percent8.1;
run;
Any ideas for how to fix this error and get the table I need?
This code solved my problem
proc sort data=table1 out=sortedtable;
by descending QuestionPercentage;
run;
proc print data=sortedtable noobs;
format QuestionPercentage percent8.1;
var QuestionPercentage Form QuestionNumber;
run;
I'm doing a simple count of occurrences of a by-variable within a class variable, but cannot find a way to rename the total count across class variables. At the moment, the output dataset includes counts for all cluster2 within each group as well as the total count across all groups (i.e. the class variable used). However, the counts within classes are named, while the total is shown by an empty string.
Code:
proc means data=seeds noprint;
class group;
by cluster2;
id label2;
output out=seeds_counts (drop= _type_ _freq_) n(id)=count;
run;
Example of output file:
cluster2 group label2 count
7 area 1 20
7 sa area 1 15
7 sb area 1 5
15 area 15 42
15 sa area 15 18
....
Naturally, renaming the emtpy string to "Total" could be accomplished in a separate datastep, but I would like to do it directly in the Proc Means-step. It should be simple and trivial, but I haven't found a way so far. Afterwards, I want to transpose the dataset, which means that the emtpy string has to be changed, or it will be dropped in the proc transpose.
I don't know of a way to do it directly, but you can sort-of-cheat: you can tell SAS to show "Total" instead of missing.
proc format;
value $MissTotalF
' ' = 'Total'
other = [$CHAR12.];
quit;
proc means data=sashelp.class noprint;
class sex;
id age;
output out=sex_counts (drop= _type_ _freq_) n(age)=count;
format sex $MissTotalF.;
run;
For example. I'd also recommend using PROC TABULATE instead of PROC MEANS if you're just going for counts, though in this case it doesn't really make much difference.
The problem here is that if the variable in the class statement is numeric, then the resultant column will be numeric, therefore you can't add the word Total (unless you use a format, similar to the answer from #Joe). This will be why the value is missing, as the class variable can be either numeric or character.
Here's an example of a numeric class variable.
proc sort data=sashelp.class out=class;
by sex;
run;
proc means data=class noprint;
class age;
by sex;
output out=class_counts (drop= _:) n=count;
run;
Using proc tabulate can display the result pretty much how you want it, however the output dataset will have the same missing values, so won't really help. Here's a couple of examples.
proc tabulate data=class out=class_tabulate1 (drop=_:);
class sex age;
table sex*(age all='Total'),n='';
run;
proc tabulate data=class out=class_tabulate2 (drop=_:);
class sex age;
table sex,age*n='' all='Total';
run;
I think the best option to achieve your final goal is to add the nway option to proc means, which will remove the subtotals, then transpose the data and finally write a data step that creates the Total column by summing each row. It's 3 steps, but doesn't involve much coding.
Here is one method you could use by taking advantage of the _TYPE_ variable so that you can process the totals and details separately. You will still have trouble with PROC TRANSPOSE if there is a class with missing values (separate from the overall summary record).
proc means data=sashelp.class noprint;
class sex;
id age;
output out=sex_counts (drop= _freq_ ) n(age)=count;
run;
proc transpose data=sex_counts out=transpose prefix=count_ ;
where _type_=1 ;
id sex ;
var count;
run;
data transpose ;
merge transpose sex_counts(where=(_type_=0) keep=_type_ count);
rename count=count_Total;
drop _type_;
run;
When I run the code below, it outputs a text file where the default hyphen for the headline option is replaced by the letter F. So I get a series of Fs dispayed across my report. Any idea what could be causing this? I've never run across this before and can't find any info about it...
proc printto print='c:\temp\test.txt';
run;
PROC REPORT DATA=SUM_2010 HEADLINE HEADSKIP MISSING nowd;
COLUMNS field1 field2;
DEFINE field1 / 'NUMBER OF things' FORMAT=COMMA20.0 WIDTH=25;
DEFINE filed2 / 'VALUE of things' FORMAT=DOLLAR28.2 WIDTH=30;
RBREAK AFTER/SKIP SUMMARIZE DOL;
TITLE1 "something";
TITLE2 "something something";
TITLE3 "more something";
TITLE4 "YEAR: 2010";
RUN;
quit;
Try the formchar option - this affects horizontal and vertical lines in proc tabulate and proc report. This should provide more appealing output => options formchar="|----||---|-/\<>*"; (run it before the proc report).
I have the following sample data and 'proc means' command.
data have;
input measure country $;
datalines;
250 UK
800 Ireland
500 Finland
250 Slovakia
3888 Slovenia
34 Portugal
44 Netherlands
4666 Austria
run;
PROC PRINT data=have; RUN;
The following PROC MEANS command prints out a listing for each country above. How can I group some of those countries (i.e. UK & Ireland, Slovakia/SLovenia as Central Europe) in the PROC MEANS step, rather than adding another datastep to add a 'case when' etc?
proc means data=have sum maxdec=2 order=freq STACKODS;
var measure;
class country;
run;
Thanks for any help at all on this. I understand there are various things you can do in the PROC MEANS command itself (like limit the number of countries by doing this:
proc means data=have(WHERE=(country not in ('Finland', 'UK')
I'd like to do the grouping in the PROC MEANS command for brevity.
Thanks.
This is very easy with a format for any PROC that takes a CLASS statement.
Simply build a format, either with code or from data; then apply the format in the PROC MEANS statement.
proc format lib=work;
value $countrygroup
"UK"="British Isles"
"Ireland"="British Isles"
"Slovakia","Slovenia"="Central Europe"
;
quit;
proc means data=have;
class country;
var measure;
format country $countrygroup.;
run;
It's usually better to have numeric codes for country and then format those to be whichever set of names is needed at any one time, particularly as capitalization/etc. is pretty irritating, but this works well enough even here.
The CNTLIN= option in PROC FORMAT allows you to make a format from a dataset, with FMTNAME as the value statement, START as the value-to-label, LABEL as the label. (END=end of range if numeric.) There are other options also, the documentation goes into more detail.