BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

I am using this code (simplified) in a macro:

 

 

PROC TRANSPOSE data=Temp out=TransTemp (drop=_:);
	by Range;
	var SomeVar;
	id Segment;
run;

proc print data=TransTemp NOOBS; 
	var Range 	
		x	
		y
		z
	;
	format 
		x
		y
		z NLMNLGBP. 
	; 	
run;

Unfortunately I sometimes only have a subset of the above columns (x, y, z) present in TransTemp. Is there anything I can do to adjust the code to dynamically adapt - i.e. macrotise it somehow?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Try this format statement:

 

format _numeric_ NLMNLGBP. range;

 

You may not need to add RANGE to the list, if it is character.  This statement assigns the format to all numeric variables being printed, but then removes any format assigned to RANGE.

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

not sure if I understood your question

 

1. do you want to list all your variable names in your transtemp dataset

2. is the problem to do with listing fewer variale names in var statement when there are fewer vars in transtemp?

 

 

csetzkorn
Lapis Lazuli | Level 10

Thanks for the reply. Yes 2 is the problem ... 

novinosrin
Tourmaline | Level 20

Well, i suppose you can do away with your var statement 

 

data w;
set sashelp.class;
run;

proc print data=w noobs;
run;

and let sas list the N number of vars in the input dataset by default without you having to mention it.

Or am i missing something here?

csetzkorn
Lapis Lazuli | Level 10

Sorry no I cannot (I think) as I want to format them. I am using:

 

format 
		x	
		y
		z percent7.1 
		; 	

or

proc format; 
 value Bla
    low -< -1.0 = "red" 
    -1 -< 0 = "green"
	0 - high = "white"; 
run;

...

/style(data) = [background=Bla.]

in my proc print statement.

Shmuel
Garnet | Level 18

You can use proc format and define all formats you need independenly from variables you want to use.

 

Assuming you want to print part of the variables in the dataset you can use KEEP statement, to keep wanted variables,

in the PROC PRINT procedure.

You can define the variables using %LET staement preceding the proc print:

%let vars = x y;  /* list of wanted variables */

proc print data=w(keep=&vars) noobs;
run;

In case you want to print all varaibles, you can assign vars to _ALL_;

Astounding
PROC Star

Try this format statement:

 

format _numeric_ NLMNLGBP. range;

 

You may not need to add RANGE to the list, if it is character.  This statement assigns the format to all numeric variables being printed, but then removes any format assigned to RANGE.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1587 views
  • 0 likes
  • 4 in conversation