DATA Step, Macro, Functions and more

label="+"||SS_year <-- what does the ||SS_year mean?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

label="+"||SS_year <-- what does the ||SS_year mean?

[ Edited ]

I'm having trouble understanding the following code, specifically starting with label="+"||SS_year;

 

i think label="+" means make a variable called "label" and populate it with "+", but I'm not sure what the "||SS_year" comes in. 

 

Also, what does fmtname="$all_pts_prev"; mean? Make a variable called "fmtname" that is populated by "$all_pts_prev"?

 

Relevant code below: 

 

data fmt_all_yrs;
	set interim.sample;
	if SS_2010=1 then SS_year='2010';
		else if SS_2011=1 then SS_year='2011';
		else if SS_2012=1 then SS_year='2012';
		else if SS_2013=1 then SS_year='2013';
		else if SS_2014=1 then SS_year='2014';
	start=strip(patient_id);
	label="+"||SS_year;
	fmtname="$all_pts_prev";
	keep start label fmtname;
run;

 

And code immediately after this says

 

proc sort nodupkey data=fmt_all_yrs 
			out=format.fmt_all_pts_prev; 
			by start;
run;

proc format cntlin=format.fmt_all_pts_prev library=format;
run;

Is this saying we're going to sort a dataset called fmt_all_yrs and output it into the library format, and call the new dataset "fmt_all_pts_prev" and organize it by the variable "start"... 

 

Not sure what the last line means though (proc format cntlin=format.fmt_all_pts_prev library=formatSmiley Wink


Accepted Solutions
Solution
a month ago
SAS Super FREQ
Posts: 309

Re: label="+"||SS_year <-- what does the ||SS_year mean?

[ Edited ]

|| concatenates character strings.

 

The code as a whole is creating a data set that will create a format--instructions for rendering a value in a data set in a particular way.  SAS provides many formats.  The 5.2 format will display 33.33333 is 33.33.  However, many times you want explicit ad hoc instructions such as display 'M' as 'Male' and display 'F' as 'Female'.  Look at the PROC FORMAT documentation and you will see examples of other CNTLIN= data set that make formats.  Values of your variable that match Start should instead be displayed as the value of Label.

 

View solution in original post


All Replies
Solution
a month ago
SAS Super FREQ
Posts: 309

Re: label="+"||SS_year <-- what does the ||SS_year mean?

[ Edited ]

|| concatenates character strings.

 

The code as a whole is creating a data set that will create a format--instructions for rendering a value in a data set in a particular way.  SAS provides many formats.  The 5.2 format will display 33.33333 is 33.33.  However, many times you want explicit ad hoc instructions such as display 'M' as 'Male' and display 'F' as 'Female'.  Look at the PROC FORMAT documentation and you will see examples of other CNTLIN= data set that make formats.  Values of your variable that match Start should instead be displayed as the value of Label.

 

Occasional Contributor
Posts: 13

Re: label="+"||SS_year <-- what does the ||SS_year mean?

Posted in reply to WarrenKuhfeld

Thank you! Super helpful and learning so much Smiley Happy

 

Two questions below.

 

1. So the $all_pts_prev doesn't seem to be a SAS format... does that mean that this coder made a new format called "$all_pts_prev" and stored it in a dataset called "fmt_all_pts_prev"? 

 

How could I set up such a format dataset myself? I don't have access to the original dataset so I'm trying to figure out what's going on here...  

 

proc sort nodupkey data=fmt_all_yrs 
			out=format.fmt_all_pts_prev; 
			by start;
run;

proc format cntlin=format.fmt_all_pts_prev library=format;
run;

 

2. What do you mean by "values of your variable that match Start should instead be displayed as the value of Label."? 

SAS Super FREQ
Posts: 309

Re: label="+"||SS_year <-- what does the ||SS_year mean?

​I think it would be good to look at the CNTLIN= example in the doc.

 

 $all_pts_prev  is not a format SAS provides.  It is the one you are making.

 

Like I said, your variable might have values like 1 or M for Male or 2 or F for Female.  So you can write a format to display Male and Female instead of the less informative values.

 

Even if you don't have the original data, print the CNTLIN data set.  The start values are like my 1, M or 2, F values.  The label values are like my Male and Female values.  Formats enable you to display custom values for any (typically more parsimonious values).

Occasional Contributor
Posts: 13

Re: label="+"||SS_year <-- what does the ||SS_year mean?

Posted in reply to WarrenKuhfeld
Thank you for the response!

So in SAS, "making" a format often means making a dataset thats like

start ... label
M.... Male
F.... Female

? I'm not sure how to print the CNTLIN data set, unfortunately Smiley Sad B/c I'm not sure I can even run this code if I don't any data? (I have none of the original data :/)
SAS Super FREQ
Posts: 309

Re: label="+"||SS_year <-- what does the ||SS_year mean?

https://blogs.sas.com/content/graphicallyspeaking/2017/10/09/advanced-ods-graphics-axis-tables-conta...

 

Here is one of my blogs.  It begins with a vanilla example of making a format by using a VALUE statement, then it shows the CNTLIN= data set approach.  I use both regularly in my work.  It just depends on whether it is more convenient to create a data set or a statement.  The content of the blog may be a bit beyond what you are looking for, but the technique is the same regardless of the problem.

Occasional Contributor
Posts: 13

Re: label="+"||SS_year <-- what does the ||SS_year mean?

Posted in reply to WarrenKuhfeld
Thanks so much! You're helping me learn SAS Smiley Happy
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 102 views
  • 1 like
  • 2 in conversation