<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Column Sorting with Proc Transpose in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374106#M24364</link>
    <description>&lt;P&gt;You can't use proc sql to both create a table and create a macro variable at the same time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following (your code with the create table removed) will produce a note that the sort will produce some missing values, but I think does what you want it to do:&lt;/P&gt;
&lt;PRE&gt;data ab;&lt;BR /&gt;  input name $ class $ dt $ gpa $;&lt;BR /&gt;  datalines;
JOHN 1 201607 C-
JOHN 1 201608 C+
JOHN 1 201702 B-
JOHN 2 201608 A
NICK 1 201608 A
NICK 1 201707 A
MIKE 2 201608 B
MIKE 2 201607 B
MIKE 2 201707 B+
MIKE 2 201702 B
BOB 3 201702 D
BOB 3 201607 C
BOB 3 201707 C
;
proc sort data=work.AB;
by NAME ClASS dt;
run;
PROC TRANSPOSE DATA = AB OUT = ABC(drop=_name_) ;
BY nAME cLASS;
VAR GPA;
ID dt;
RUN ;
proc sql noprint;
/* create table test as */
select name into : list separated by ' '
from dictionary.columns
where libname='WORK' and memname='ABC'
order by input(substr(name,anydigit(name)),best32.)
;
quit;
%put &amp;amp;list;
data want;
retain &amp;amp;list;
set ABC;
run;

&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: added the initial data and input statements that were originally omitted from my post&lt;/P&gt;</description>
    <pubDate>Sun, 09 Jul 2017 20:35:20 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-07-09T20:35:20Z</dc:date>
    <item>
      <title>Column Sorting with Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374090#M24363</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;I am using below mentioned code to get the columns sorted dynamically after proc transpose. I have gone a lot of solutions for this solution. But now I am getting an error if I run&lt;BR /&gt;data work.AB ;&lt;BR /&gt;input name $ class $ dt $ gpa $;&lt;BR /&gt;datalines;&lt;BR /&gt;JOHN 1 201607 C-&lt;BR /&gt;JOHN 1 201608 C+&lt;BR /&gt;JOHN 1 201702 B-&lt;BR /&gt;JOHN 2 201608 A&lt;BR /&gt;NICK 1 201608 A&lt;BR /&gt;NICK 1 201707 A&lt;BR /&gt;MIKE 2 201608 B&lt;BR /&gt;MIKE 2 201607 B&lt;BR /&gt;MIKE 2 201707 B+&lt;BR /&gt;MIKE 2 201702 B&lt;BR /&gt;BOB 3 201702 D&lt;BR /&gt;BOB 3 201607 C&lt;BR /&gt;BOB 3 201707 C&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sort data=work.AB;&lt;BR /&gt;by NAME ClASS dt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;PROC TRANSPOSE DATA = AB OUT = ABC(drop=_name_) ;&lt;BR /&gt;BY nAME cLASS;&lt;BR /&gt;VAR GPA;&lt;BR /&gt;ID dt;&lt;BR /&gt;RUN ;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;create table test as&lt;BR /&gt;select name into : list separated by ' '&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where libname='WORK' and memname='ABC'&lt;BR /&gt;order by input(substr(name,anydigit(name)),best32.)&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;list;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;retain &amp;amp;list;&lt;BR /&gt;set ABC;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Error that I get is&lt;BR /&gt;22 GOPTIONS ACCESSIBLE;&lt;BR /&gt;WARNING: Apparent symbolic reference LIST not resolved.&lt;BR /&gt;23 %put &amp;amp;list;&lt;BR /&gt;&amp;amp;list&lt;BR /&gt;24 data want;&lt;BR /&gt;25 retain &amp;amp;list;&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;200&lt;BR /&gt;WARNING: Apparent symbolic reference LIST not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.&lt;BR /&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;BR /&gt;26 set ABC;&lt;BR /&gt;27 run;&lt;/P&gt;&lt;P&gt;Kindly suggest.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 20:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374090#M24363</guid>
      <dc:creator>Aditya81769</dc:creator>
      <dc:date>2017-07-07T20:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Column Sorting with Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374106#M24364</link>
      <description>&lt;P&gt;You can't use proc sql to both create a table and create a macro variable at the same time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following (your code with the create table removed) will produce a note that the sort will produce some missing values, but I think does what you want it to do:&lt;/P&gt;
&lt;PRE&gt;data ab;&lt;BR /&gt;  input name $ class $ dt $ gpa $;&lt;BR /&gt;  datalines;
JOHN 1 201607 C-
JOHN 1 201608 C+
JOHN 1 201702 B-
JOHN 2 201608 A
NICK 1 201608 A
NICK 1 201707 A
MIKE 2 201608 B
MIKE 2 201607 B
MIKE 2 201707 B+
MIKE 2 201702 B
BOB 3 201702 D
BOB 3 201607 C
BOB 3 201707 C
;
proc sort data=work.AB;
by NAME ClASS dt;
run;
PROC TRANSPOSE DATA = AB OUT = ABC(drop=_name_) ;
BY nAME cLASS;
VAR GPA;
ID dt;
RUN ;
proc sql noprint;
/* create table test as */
select name into : list separated by ' '
from dictionary.columns
where libname='WORK' and memname='ABC'
order by input(substr(name,anydigit(name)),best32.)
;
quit;
%put &amp;amp;list;
data want;
retain &amp;amp;list;
set ABC;
run;

&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: added the initial data and input statements that were originally omitted from my post&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 20:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374106#M24364</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-09T20:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Column Sorting with Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374316#M24368</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have tried the way you that you have suggested&lt;BR /&gt;But I am still getting the same error&lt;BR /&gt;&lt;BR /&gt;Kindly suggest&lt;BR /&gt;Thank you for the help</description>
      <pubDate>Sun, 09 Jul 2017 20:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374316#M24368</guid>
      <dc:creator>Aditya81769</dc:creator>
      <dc:date>2017-07-09T20:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Column Sorting with Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374320#M24370</link>
      <description>&lt;P&gt;The initial data and input statements were somehow omitted from the code I proposed (I'll add them to the original post).&lt;/P&gt;
&lt;P&gt;The following worked for me:&lt;/P&gt;
&lt;PRE&gt;data ab;
  input name $ class $ dt $ gpa $;
  datalines;
JOHN 1 201607 C-
JOHN 1 201608 C+
JOHN 1 201702 B-
JOHN 2 201608 A
NICK 1 201608 A
NICK 1 201707 A
MIKE 2 201608 B
MIKE 2 201607 B
MIKE 2 201707 B+
MIKE 2 201702 B
BOB 3 201702 D
BOB 3 201607 C
BOB 3 201707 C
;
proc sort data=work.AB;
by NAME ClASS dt;
run;
PROC TRANSPOSE DATA = AB OUT = ABC(drop=_name_) ;
BY nAME cLASS;
VAR GPA;
ID dt;
RUN ;
proc sql noprint;
/* create table test as */
select name into : list separated by ' '
from dictionary.columns
where libname='WORK' and memname='ABC'
order by input(substr(name,anydigit(name)),best32.)
;
quit;
%put &amp;amp;list;
data want;
retain &amp;amp;list;
set ABC;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 20:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374320#M24370</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-09T20:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Column Sorting with Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374369#M24374</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any solution for the error which I am getting. If I try to run the same code which you have suggested I get the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the log windo that I am getting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 The SAS System 09:15 Friday, July 7, 2017&lt;/P&gt;&lt;P&gt;1 ;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 %LET _CLIENTTASKLABEL='Program';&lt;BR /&gt;4 %LET _CLIENTPROJECTPATH='';&lt;BR /&gt;5 %LET _CLIENTPROJECTNAME='';&lt;BR /&gt;6 %LET _SASPROGRAMFILE=;&lt;BR /&gt;7&lt;BR /&gt;8 ODS _ALL_ CLOSE;&lt;BR /&gt;9 OPTIONS DEV=ACTIVEX;&lt;BR /&gt;10 GOPTIONS XPIXELS=0 YPIXELS=0;&lt;BR /&gt;11 FILENAME EGSR TEMP;&lt;BR /&gt;12 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR&lt;BR /&gt;13 STYLE=HtmlBlue&lt;BR /&gt;14 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")&lt;BR /&gt;15 NOGTITLE&lt;BR /&gt;16 NOGFOOTNOTE&lt;BR /&gt;17 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;18 ENCODING=UTF8&lt;BR /&gt;19 options(rolap="on")&lt;BR /&gt;20 ;&lt;BR /&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR&lt;BR /&gt;21&lt;BR /&gt;22 GOPTIONS ACCESSIBLE;&lt;BR /&gt;23 data work.AB ;&lt;BR /&gt;24 input name $ class $ dt $ gpa $;&lt;BR /&gt;25 /* calendardate=mdy(scan(dt,1),scan(dt,2),scan(dt,3)); */&lt;BR /&gt;26 /* format calendardate mmddyy10.;*/&lt;BR /&gt;27 datalines;&lt;/P&gt;&lt;P&gt;NOTE: SAS went to a new line when INPUT statement reached past the end of a line.&lt;BR /&gt;NOTE: The data set WORK.AB has 13 observations and 4 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.02 seconds&lt;BR /&gt;&lt;BR /&gt;42 ;&lt;/P&gt;&lt;P&gt;43&lt;BR /&gt;44 proc sort data=work.AB;&lt;BR /&gt;45 by NAME ClASS dt;&lt;BR /&gt;46 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 13 observations read from the data set WORK.AB.&lt;BR /&gt;NOTE: The data set WORK.AB has 13 observations and 4 variables.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;47&lt;BR /&gt;48 PROC TRANSPOSE DATA = AB OUT = ABC(drop=_name_) ;&lt;BR /&gt;49 BY nAME cLASS;&lt;BR /&gt;50 VAR GPA;&lt;BR /&gt;51 ID dt;&lt;BR /&gt;52 RUN ;&lt;/P&gt;&lt;P&gt;NOTE: There were 13 observations read from the data set WORK.AB.&lt;BR /&gt;NOTE: The data set WORK.ABC has 5 observations and 6 variables.&lt;BR /&gt;2 The SAS System 09:15 Friday, July 7, 2017&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE TRANSPOSE used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;53&lt;BR /&gt;54 proc sql noprint;&lt;BR /&gt;55 /*create table test as */&lt;BR /&gt;56 select name into : list separated by ' '&lt;BR /&gt;57 from dictionary.columns&lt;BR /&gt;58 where libname='WORK' and memname='ABC'&lt;BR /&gt;59 order by input(substr(name,anydigit(name)),best32.)&lt;BR /&gt;60 ;&lt;BR /&gt;NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause.&lt;BR /&gt;NOTE: Invalid argument 2 to function SUBSTR. Missing values may be generated.&lt;BR /&gt;61 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.02 seconds&lt;/P&gt;&lt;P&gt;62 %put &amp;amp;list;&lt;BR /&gt;class name 201607 201608 201702 201707&lt;BR /&gt;63 data want;&lt;BR /&gt;64 retain &amp;amp;list;&lt;BR /&gt;NOTE: Line generated by the macro variable "LIST".&lt;BR /&gt;64 class name 201607 201608 201702 201707&lt;BR /&gt;______&lt;BR /&gt;22&lt;BR /&gt;200&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;65 set ABC;&lt;BR /&gt;ERROR: Variable name has been defined as both character and numeric.&lt;BR /&gt;ERROR: Variable class has been defined as both character and numeric.&lt;BR /&gt;66 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 5 variables.&lt;BR /&gt;WARNING: Data set WORK.WANT was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;67&lt;BR /&gt;68&lt;BR /&gt;69 GOPTIONS NOACCESSIBLE;&lt;BR /&gt;70 %LET _CLIENTTASKLABEL=;&lt;BR /&gt;71 %LET _CLIENTPROJECTPATH=;&lt;BR /&gt;72 %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;73 %LET _SASPROGRAMFILE=;&lt;BR /&gt;74&lt;BR /&gt;75 ;*';*";*/;quit;run;&lt;BR /&gt;76 ODS _ALL_ CLOSE;&lt;BR /&gt;77&lt;BR /&gt;3 The SAS System 09:15 Friday, July 7, 2017&lt;/P&gt;&lt;P&gt;78&lt;BR /&gt;79 QUIT; RUN;&lt;BR /&gt;80&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 04:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374369#M24374</guid>
      <dc:creator>Aditya81769</dc:creator>
      <dc:date>2017-07-10T04:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Column Sorting with Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374375#M24375</link>
      <description>&lt;P&gt;Your log doesn't show it, but my best guess is that you have the SAS option VALIDVARNAME set to the value ANY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run the following line before running the code:&lt;/P&gt;
&lt;PRE&gt;options validvarname=v7;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 05:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Column-Sorting-with-Proc-Transpose/m-p/374375#M24375</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-10T05:21:53Z</dc:date>
    </item>
  </channel>
</rss>

