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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 1130 views
  • 0 likes
  • 4 in conversation