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
Opal | Level 21

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
Opal | Level 21

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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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