<?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: Is there one way to drop last variable always? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414300#M101497</link>
    <description>&lt;P&gt;There is probably a smarter way, but you could do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var1-var3;
datalines;
1 2 3
4 5 6
7 8 9
;

ods select Variables;
proc contents data=have;
	ods output Variables=var;
run;

proc sort data=var;
	by Num;
run;

data _null_;
	set var;
	by num;
	if last.num then call symputx('lastvar', Variable);
run;

%put The last variable is &amp;amp;lastvar;

data want;
	set have;
	drop &amp;amp;lastvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Nov 2017 09:50:59 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-11-17T09:50:59Z</dc:date>
    <item>
      <title>Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414297#M101494</link>
      <description>&lt;P&gt;I want to drop last variable but i dont know how.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do in SAS?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 09:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414297#M101494</guid>
      <dc:creator>dali74</dc:creator>
      <dc:date>2017-11-17T09:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414298#M101495</link>
      <description>&lt;P&gt;What do you mean by last variable?&lt;/P&gt;
&lt;P&gt;Can you post a sample of data and point at what do you wand to drop ?!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 09:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414298#M101495</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-17T09:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414299#M101496</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data matriz;
INPUT x1-x3 var @@;
datalines;
20	6	14	1
21	6	18	2
20	6	14	3
24	6	45	5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If we have this code i want to drop variable named "var". but i can have more variables in the future and i want drop last variable always, because his position is always the last one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 09:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414299#M101496</guid>
      <dc:creator>dali74</dc:creator>
      <dc:date>2017-11-17T09:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414300#M101497</link>
      <description>&lt;P&gt;There is probably a smarter way, but you could do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var1-var3;
datalines;
1 2 3
4 5 6
7 8 9
;

ods select Variables;
proc contents data=have;
	ods output Variables=var;
run;

proc sort data=var;
	by Num;
run;

data _null_;
	set var;
	by num;
	if last.num then call symputx('lastvar', Variable);
run;

%put The last variable is &amp;amp;lastvar;

data want;
	set have;
	drop &amp;amp;lastvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 09:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414300#M101497</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-17T09:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414304#M101499</link>
      <description>&lt;P&gt;Yes it works fine but i´m using this code and it always put 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    select  count (varnum) into :numvar
    from    dictionary.COLUMNS
	 where upcase(LIBNAME) =  "WORK"  and
     upcase(MEMNAME) = "matriz";
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First i´m looking for number of vars and i will delete it after.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 10:14:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414304#M101499</guid>
      <dc:creator>dali74</dc:creator>
      <dc:date>2017-11-17T10:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414307#M101500</link>
      <description>&lt;P&gt;1. this code returns zero because you use the UPCASE Function and do not upcase the string "matriz". It should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    select  count (varnum) into :numvar
    from    dictionary.COLUMNS
	 where upcase(LIBNAME) =  "&lt;FONT color="#800000"&gt;WORK&lt;/FONT&gt;"  and
     upcase(MEMNAME) = "MATRIZ";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. Why? This code will give you the number of colums in your data set. How do you go from there to actually dropping the numvar'th variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 10:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414307#M101500</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-17T10:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414309#M101501</link>
      <description>&lt;P&gt;Retrieve the information from dictionary.columns, and store into a macro variable used for dropping:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data matriz;
INPUT x1-x3 var;
datalines;
20 6 14 1
21 6 18 2
20 6 14 3
24 6 45 5
;
run;

proc sql noprint;
select name into:lastvar
from dictionary.columns
where libname='WORK' and memname='MATRIZ'
having varnum=max(varnum)
;
quit;

%put &amp;amp;lastvar; * for control purposes;

data matriz_new;
set matriz;
drop &amp;amp;lastvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 10:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414309#M101501</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-17T10:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414312#M101502</link>
      <description>&lt;P&gt;Out of interest, what is the logical reason for always removing the last variable?&amp;nbsp; It sounds a bit like your doing some processing on lots of datasets and then trying to fix it later on.&amp;nbsp; Its highly likely that a simple change to the process would remove the need for this at all.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 10:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414312#M101502</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-17T10:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414332#M101509</link>
      <description>Problaby you are right. I need to save last variable in other dataset.</description>
      <pubDate>Fri, 17 Nov 2017 10:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414332#M101509</guid>
      <dc:creator>dali74</dc:creator>
      <dc:date>2017-11-17T10:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414355#M101516</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
 set sashelp.class;
run;

proc transpose data=class(obs=0) out=temp;
var _all_;
run;
data _null_;
 set temp point=nobs nobs=nobs;
 call execute(cat('data want;set class;drop ',_name_,';run;'));
 stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 13:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414355#M101516</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-17T13:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414649#M101604</link>
      <description>&lt;P&gt;How weight variable deleted? As per my understanding&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The NOBS = option creates a variable which contains the total number of observations in the input data set(s). If multiple data sets are listed in the SET statement, the value in the NOBS = variable are the total number of observations in all the listed data sets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is read in online. Can some one explain it...&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 10:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414649#M101604</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-11-19T10:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414650#M101605</link>
      <description>&lt;P&gt;Proc transpose (when used in this way) creates a dataset with observations (rows) for columns, so the last observation will contain the name of the last variable in _name_.&lt;/P&gt;
&lt;P&gt;The point=nobs nobs=nobs option combination will read exactly this last observation from the transposed dataset.&lt;/P&gt;
&lt;P&gt;Note that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s solution reads the dataset twice (and additionally writes the transposed dataset), while mine (using the table metadata) only needs one read of the complete dataset. I guess it's just to show how many ways one can find in SAS to solve a specific issue.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 10:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414650#M101605</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-19T10:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414651#M101606</link>
      <description>&lt;P&gt;Thank you... and one more thing in your code SQl "select" statement&amp;nbsp;I seen name variable but it not found in source data set How it going to work...(I'm seen X1-X3 and var variable's)&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 10:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414651#M101606</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-11-19T10:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414652#M101607</link>
      <description>&lt;P&gt;Check this out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p00cato8pe46ein1bjcimkkx6hzd.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=da" target="_self"&gt;How to View Dictionary Tables&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 10:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414652#M101607</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-19T10:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: Is there one way to drop last variable always?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414653#M101608</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174522"&gt;@rajeshalwayswel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you... and one more thing in your code SQl "select" statement&amp;nbsp;I seen name variable but it not found in source data set How it going to work...(I'm seen X1-X3 and var variable's)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Look closely. The SQL reads from dictionary.columns, which is a dynamically populated meta-dataset. Google for "sas dictionary tables" to see what you can get from them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although syntactically not reading from the source dataset, technically it reads the file header and retrieves the dataset's structural information.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 10:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-one-way-to-drop-last-variable-always/m-p/414653#M101608</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-19T10:56:25Z</dc:date>
    </item>
  </channel>
</rss>

