Help using Base SAS procedures

proc print - dynamic vars

Accepted Solution Solved
Reply
Regular Contributor
Posts: 204
Accepted Solution

proc print - dynamic vars

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?

 


Accepted Solutions
Solution
‎05-14-2018 05:54 AM
Super User
Posts: 6,754

Re: proc print - dynamic vars

Posted in reply to csetzkorn

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


All Replies
PROC Star
Posts: 1,772

Re: proc print - dynamic vars

Posted in reply to csetzkorn

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?

 

 

Regular Contributor
Posts: 204

Re: proc print - dynamic vars

Posted in reply to novinosrin

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

PROC Star
Posts: 1,772

Re: proc print - dynamic vars

Posted in reply to csetzkorn

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?

Regular Contributor
Posts: 204

Re: proc print - dynamic vars

Posted in reply to novinosrin

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.

Trusted Advisor
Posts: 1,837

Re: proc print - dynamic vars

Posted in reply to csetzkorn

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

Solution
‎05-14-2018 05:54 AM
Super User
Posts: 6,754

Re: proc print - dynamic vars

Posted in reply to csetzkorn

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.

☑ This topic is solved.

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

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