BookmarkSubscribeRSS Feed
piggy
Fluorite | Level 6
Hi,

Anyone could help?


Data test;
set sample;
if Variable_1 >3.5 comments ="Old";
else Comments ="New";
run;

SAS would automatically put "Comments" at the end. If I already have 80 varialbes, "Comments" would be the 81th. How can I put "comments" in front of other varibles. So, when I export final results into excel, I don't have to scroll down to the end to see my comments.

I can use proc sql or retain statment to reorder my variables, but is there any better way? I have more than 80 varibles and I use proc import to import data, so every time the 80 varibles could have different names.
5 REPLIES 5
art297
Opal | Level 21
Since you only want to move your Comments variable, that is the only variable that has to be on the retain or length statment. And, since you probably have to assign a length to the variable, I'd use the length statement to accomplish the task. Thus, the following should do what you want:

data test;
length Comments $ 250;
set sashelp.class (rename=(
age=Variable_1));
if Variable_1 >14 then comments ="Old";
else Comments ="New";
run;

HTH,
Art
piggy
Fluorite | Level 6
Thanks art297.
Ksharp
Super User
Hi.
art297's idea is great . I like it.
and I also have a method.You can change the order of variable as you want.

[pre]
data test;
set sashelp.class ;
if age >14 then comments ="Old";
else Comments ="New";
run;
proc report data=test nowd out=temp(drop=_break_);
column comments name -- weight; * name is your first variable ,weight is your last variable;
run;
proc print noobs;
run;
[/pre]



Ksharp
chang_y_chung_hotmail_com
Obsidian | Level 7
@Ksharp: Re-ordering variables using PROC REPORT is new to me. It seems to variable-label as well, unless the var already has one. Interesting!
[pre]
data test;
set sashelp.class ;
if age >14 then comments ="Old";
else Comments ="New";
label age="age at last birthday";
run;

/* re-order vars using proc report -- it var labels as well */
proc report data=test nowd out=temp(drop=_break_);
column comments name -- weight;
run;

/* check */
proc compare data=test compare=temp;
run;
/* on lst -- in part
...
Number of Variables in Common: 6.
Number of Variables with Differing Attributes: 5.
...
NOTE: No unequal values were found. All values compared are exactly equal.
*/
[/pre]
Ksharp
Super User
🙂
Yes. I am also curious that proc report would create variable label by using variable name automatically,when this variable has no label.And move the variable with it's label.

From your id name , I guess you are chinese boy ??
I am too.


Ksharp

Message was edited by: Ksharp

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!

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
  • 5 replies
  • 881 views
  • 0 likes
  • 4 in conversation