sunrain Tracker
https://communities.sas.com/kntur85557/tracker
sunrain TrackerSat, 14 Sep 2024 05:13:26 GMT2024-09-14T05:13:26ZRe: help needed to create a macro var as x1 x2 ...xn where n is not determined
https://communities.sas.com/t5/SAS-Programming/help-needed-to-create-a-macro-var-as-x1-x2-xn-where-n-is-not/m-p/71368#M15450
Thank you, Andrea.<BR />
I would like a macro var to contain these variable names, not a list of macro vars.<BR />
Sorry that I misled you.<BR />
<BR />
SunrainTue, 31 May 2011 11:42:08 GMThttps://communities.sas.com/t5/SAS-Programming/help-needed-to-create-a-macro-var-as-x1-x2-xn-where-n-is-not/m-p/71368#M15450sunrain2011-05-31T11:42:08Zhelp needed to create a macro var as x1 x2 ...xn where n is not determined
https://communities.sas.com/t5/SAS-Programming/help-needed-to-create-a-macro-var-as-x1-x2-xn-where-n-is-not/m-p/71366#M15448
Dear Helper:<BR />
<BR />
I am trying to create a macro var as x1 x2 ...xn, where the number n should be determined by another macro var.<BR />
<BR />
SunrainTue, 31 May 2011 11:13:12 GMThttps://communities.sas.com/t5/SAS-Programming/help-needed-to-create-a-macro-var-as-x1-x2-xn-where-n-is-not/m-p/71366#M15448sunrain2011-05-31T11:13:12ZHow to rename all the variables as X1-X10?
https://communities.sas.com/t5/SAS-Procedures/How-to-rename-all-the-variables-as-X1-X10/m-p/70112#M20176
Hi, everyone:<BR />
<BR />
Finally I found that call sortn can be used to sort data observation wise.<BR />
But the restriction is that the names in the array should be uniform as X1-X10. Otherwise the command does not work with out warning. <BR />
<BR />
Can anybody teach me to rename all the variables such as X1-X10?Thu, 26 May 2011 18:09:54 GMThttps://communities.sas.com/t5/SAS-Procedures/How-to-rename-all-the-variables-as-X1-X10/m-p/70112#M20176sunrain2011-05-26T18:09:54Zcall sortn can work for this issue How to sort colums in numeric order?
https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69568#M19997
Hi, every one:<BR />
The command call sortn can work for this issue with some restriction.<BR />
The varnames should be as x1-x10.<BR />
<BR />
SunrainThu, 26 May 2011 18:04:02 GMThttps://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69568#M19997sunrain2011-05-26T18:04:02ZRe: How to sort colums in numeric order? How to replicate the observations?
https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69567#M19996
Hi, John:<BR />
<BR />
Maybe I did not put my question clear. My goal is to sort data in "row-wise". That is sort every row independently, that is what R sort function do. In default, R sort sorts column wise.<BR />
<BR />
That is why transpose and sort and transpose back does not work.<BR />
<BR />
Sunrain.<BR />
<BR />
<BR />
> Gday sunrain,<BR />
> <BR />
> A <I>PROC SORT</I> should do the trick for rows.<BR />
> <BR />
> For columns, I would like to know if there's a<BR />
> function/proc which will do this too.<BR />
> <BR />
> My current strategy would probably be:<BR />
> * PROC CONTENTS - to get a listing of the variables<BR />
> * sorting that list<BR />
> * creating a macro variable with the contents of the<BR />
> above list<BR />
> * in a new datastep use the ATTRIB statement to with<BR />
> the macro variable above <BR />
> <BR />
> eg<BR />
> [pre]<BR />
> <BR />
> proc contents data = sashelp.adomsg out = a_contents<BR />
> noprint;<BR />
> run;<BR />
> <BR />
> proc sort data = a_contents (keep = name) out =<BR />
> a_sort;<BR />
> by name;<BR />
> ;<BR />
> <BR />
> data _null_;<BR />
> set a_sort;<BR />
> by name;<BR />
> retain sort_vars;<BR />
> length sort_vars $100.;<BR />
> <BR />
> if _n_ = 1 then <BR />
> sort_vars = name;<BR />
> else<BR />
> sort_vars = catx(' ', sort_vars, name);<BR />
> all symput('sort_vars', sort_vars);<BR />
> run;<BR />
> %put &sort_vars.;<BR />
> <BR />
> data a_column_sorted;<BR />
> attrib &sort_vars. label = '';<BR />
> set sashelp.adomsg;<BR />
> run;<BR />
> [/pre]<BR />
> <BR />
> I don't think PROC TRANSPOSE necessarily sorts the<BR />
> columns, I think it'll probably list variables<BR />
> according the order in which in comes across them.<BR />
> <BR />
> As for efficiency, I guess that really depends on<BR />
> what the system can handle. If you want to replicate<BR />
> observations, you could have multiple OUTPUT<BR />
> statements in your code.<BR />
> <BR />
> [/pre]<BR />
> data a_replicated;<BR />
> set sashelp.adomsg;<BR />
> output;<BR />
> output;<BR />
> un;<BR />
> <BR />
> <BR />
> data a_replicated2;<BR />
> set sashelp.adomsg<BR />
> sashelp.adomsg;<BR />
> <BR />
> [/pre]<BR />
> <BR />
> The second one is concatenating the data with itself.Thu, 26 May 2011 02:09:03 GMThttps://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69567#M19996sunrain2011-05-26T02:09:03ZRe: How to sort colums in numeric order? How to replicate the observations?
https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69566#M19995
Hi, John: <BR />
<BR />
I tried your codes. I did not get the results correct. So I think I can transpose the data, sort and transpose it back. I don't care about the column names.<BR />
<BR />
Thanks.<BR />
> Gday sunrain,<BR />
> <BR />
> A <I>PROC SORT</I> should do the trick for rows.<BR />
> <BR />
> For columns, I would like to know if there's a<BR />
> function/proc which will do this too.<BR />
> <BR />
> My current strategy would probably be:<BR />
> * PROC CONTENTS - to get a listing of the variables<BR />
> * sorting that list<BR />
> * creating a macro variable with the contents of the<BR />
> above list<BR />
> * in a new datastep use the ATTRIB statement to with<BR />
> the macro variable above <BR />
> <BR />
> eg<BR />
> [pre]<BR />
> <BR />
> proc contents data = sashelp.adomsg out = a_contents<BR />
> noprint;<BR />
> run;<BR />
> <BR />
> proc sort data = a_contents (keep = name) out =<BR />
> a_sort;<BR />
> by name;<BR />
> ;<BR />
> <BR />
> data _null_;<BR />
> set a_sort;<BR />
> by name;<BR />
> retain sort_vars;<BR />
> length sort_vars $100.;<BR />
> <BR />
> if _n_ = 1 then <BR />
> sort_vars = name;<BR />
> else<BR />
> sort_vars = catx(' ', sort_vars, name);<BR />
> all symput('sort_vars', sort_vars);<BR />
> run;<BR />
> %put &sort_vars.;<BR />
> <BR />
> data a_column_sorted;<BR />
> attrib &sort_vars. label = '';<BR />
> set sashelp.adomsg;<BR />
> run;<BR />
> [/pre]<BR />
> <BR />
> I don't think PROC TRANSPOSE necessarily sorts the<BR />
> columns, I think it'll probably list variables<BR />
> according the order in which in comes across them.<BR />
> <BR />
> As for efficiency, I guess that really depends on<BR />
> what the system can handle. If you want to replicate<BR />
> observations, you could have multiple OUTPUT<BR />
> statements in your code.<BR />
> <BR />
> [/pre]<BR />
> data a_replicated;<BR />
> set sashelp.adomsg;<BR />
> output;<BR />
> output;<BR />
> un;<BR />
> <BR />
> <BR />
> data a_replicated2;<BR />
> set sashelp.adomsg<BR />
> sashelp.adomsg;<BR />
> <BR />
> [/pre]<BR />
> <BR />
> The second one is concatenating the data with itself.Thu, 26 May 2011 01:40:40 GMThttps://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69566#M19995sunrain2011-05-26T01:40:40ZHow to sort colums in numeric order? How to replicate the observations?
https://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69564#M19993
Hi, everyone:<BR />
<BR />
I just came out from the R world and started using SAS recently.<BR />
In R, there is a function apply, where you can specify sort the data across the rows or columns. In SAS, do we have to transpose the data in order to use sort?<BR />
<BR />
Also I would like to replicate each observation for several times, is there an efficient way to do that? Or I can repeat the data for k times, concatenate them and sort the whole data by ID. I can use append recursively for that. Is that efficient considering my original data has million obs? <BR />
<BR />
Thank you in advance.<BR />
SunrainWed, 25 May 2011 21:03:29 GMThttps://communities.sas.com/t5/SAS-Procedures/How-to-sort-colums-in-numeric-order-How-to-replicate-the/m-p/69564#M19993sunrain2011-05-25T21:03:29Z