Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specifying Variable Order in the Output table???

Status
Not open for further replies.

RookieDBO

Technical User
Sep 20, 2001
83
0
0
CA
How do you create a SAS table using proc report? I want to create a table specifying the order of variables. I was told this is the best way to do it. Is this true? I also tried "Drop" and "Attrib" option but couldn't get it to work. What's the fast and efficient way to do it?


proc report data=practice.Xmas_in_out_checklist_2001;
column Item_Num Category Description;
run;

Thanks,
RookieDBO

 
To create a SAS dataset with variables in a certain order, I find it easier to do it using the retain statement in the data step.... eg:

data y; set practice.xmas_in_out_checklist_2001;
retain item_num category description;
run;


If you do a PROC PRINT on dataset Y you should see the variables in the order you specify.

You can also do it in proc report but it would involve more codes---- not worth it unless you are creating a report at the same time.
 
Hi. That didn't quite work. It created an identical table.
Anymore solutions?

Thanks,
RookieDBO
 
Aren't there any SAS programmer in here??? Why doesn't anybody uses SAS? And why is it so hard to find SAS help? Does anyone know a good SAS forum?
 
Without having access to SAS at this very moment, I cannot check out why my previous solution didn't work (sorry about that).

Another solution is to try PROC SQL and specify your variable order in there.

PROC SQL;
CREATE TABLE Y AS
SELECT item_num, category, description
FROM practice.xmas_in_out_checklist_2001;

There is a SAS-L email discussion list which you can subscribe to (and I believe a web discussion forum is now available also)--- I don't have the URL but you may want to just do a search of SAS-L on Yahoo or Google?
 
The example was flawed......

Instead of this:
data y; set practice.xmas_in_out_checklist_2001;
retain item_num category description;
run;

Do this:
data y; retain item_num category description;
set practice.xmas_in_out_checklist_2001;
run;

 
On some of the other points, I'm 99% certain that DROP= and ATTRIB= are not options associated with PROC REPORT - this probably does not help!

What did the log say when you tried the code you specified?

I'm not sure about x1bobx2's example - retain is used to create static variables (also, putting two statements on one line is not recommended in my book). The keep option should have been used within the data line rather than using a retain statement. In any event I don't think it's good practice to create extra datasets when the existing one will do for the purposes of PROC REPORT.

The column statement you've quoted should work. If you want to set the attributes of the data columns you need a further statement in teh PROC step - DEFINE.

Hope this helps. SuperBry!
 
x1bobx2's works.

you can also use format or informat instead of retain. thing is, you have to put the statement before the set statement. ohterwise the variables are created by the set and you can not take influence with any following statement on the order of the variables.
when you use retain/format/informat before the set, the variables are created by that statement and thereby in that order specified. the order of the statement is the trick, not the statement.

and by the way. you can specify as many statements in one row as you want to. that the sense of the semicolon. it seperates the statements from each other. if it is not recommended that might be because of stylistic/readability reasons not because your code might not work.

DROP= and ATTRIB= are no statements. statements are associated with procedures (DROP ... and ATTRIB ... would be statements). DROP= and ATTRIB= are data set options. you specify them in parantheses after the data set name. you can use them anywhere a set is named.

hope that helps
axel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top