BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cdubs
Quartz | Level 8

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=format;)

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Rhodochrosite | Level 12

|| 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

6 REPLIES 6
WarrenKuhfeld
Rhodochrosite | Level 12

|| 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.

 

cdubs
Quartz | Level 8

Thank you! Super helpful and learning so much 🙂

 

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."? 

WarrenKuhfeld
Rhodochrosite | Level 12

​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).

cdubs
Quartz | Level 8
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 😞 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 :/)
WarrenKuhfeld
Rhodochrosite | Level 12

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.

cdubs
Quartz | Level 8
Thanks so much! You're helping me learn SAS 🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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