<?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: how to add a new variable into an existing dataset using metadata function in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889233#M43466</link>
    <description>&lt;P&gt;Ahh, I see.&amp;nbsp; It's always risky to say "no" when someone asks if it's possible to do something in SAS, but I don't think you can use the metadata functions for adding variables.&amp;nbsp; In order to add a variable to a dataset, SAS has to rewrite the dataset (header metadata and data).&amp;nbsp; That is a job for the DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If by tiny chance your goal is to write a function-style macro that would add variables to a dataset, that would be possible (using DOSUBL) but it would still use a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Aug 2023 18:38:24 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-08-14T18:38:24Z</dc:date>
    <item>
      <title>how to add a new variable into an existing dataset using metadata function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889197#M43461</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know if there is a way to add a new variable to an existing dataset without creating the updated dataset (i,e, the existing dataset with the new variable added).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know if there is a way add a new variable but without having to create the dataset&lt;BR /&gt;see code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro VarExist(dsn=,varname=);
%let dsn2=&amp;amp;dsn.;
%local dsid vnum;
%let vnum=0;
%let dsid = %sysfunc(open(&amp;amp;dsn));
%if &amp;amp;dsid %then %do;
 %let vnum = %sysfunc(varnum(&amp;amp;dsid,&amp;amp;varname));
 %let dsid = %sysfunc(close(&amp;amp;dsid));
%end;
&amp;amp;vnum
%mend ;

data test;
set sashelp.class;
run;

%if %varexist(dsn=test,varname= New_Variable ) = 0 %then 
	%do;
		data &amp;amp;dsn2.;
		%put &amp;amp;=dsn2.;
		attrib New_Variable	label="New Variable" 	length=$5. 	format=$5. 	informat=$5.;
		set &amp;amp;dsn2.;
		run;
	%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 14:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889197#M43461</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2023-08-14T14:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a new variable into an existing dataset using metadata function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889201#M43462</link>
      <description>&lt;P&gt;Can you describe your question a bit more?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to add a variable to an existing dataset, then by definition that dataset will be updated (actually over-written) when you add a variable to it.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 15:24:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889201#M43462</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-14T15:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a new variable into an existing dataset using metadata function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889222#M43465</link>
      <description>&lt;P&gt;in the SAS code,&amp;nbsp; more precisely at the if condition,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using an attribute statement with a set statement to update the dataset as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %varexist(dsn=test,varname= New_Variable ) = 0 %then 
	%do;
		data &amp;amp;dsn2.;
		%put &amp;amp;=dsn2.;
		attrib New_Variable	label="New Variable" 	length=$5. 	format=$5. 	informat=$5.;
		set &amp;amp;dsn2.;
		run;
	%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I wonder if it could be possible to add&amp;nbsp; a new variable&amp;nbsp; with the dataset identifier&lt;/P&gt;
&lt;P&gt;as below and if so, how do we do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid = %sysfunc(open(&amp;amp;dsn));
%if &amp;amp;dsid %then %do;
adding the new variable with its name, label and format.
 %let dsid = %sysfunc(close(&amp;amp;dsid));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 18:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889222#M43465</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2023-08-14T18:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a new variable into an existing dataset using metadata function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889233#M43466</link>
      <description>&lt;P&gt;Ahh, I see.&amp;nbsp; It's always risky to say "no" when someone asks if it's possible to do something in SAS, but I don't think you can use the metadata functions for adding variables.&amp;nbsp; In order to add a variable to a dataset, SAS has to rewrite the dataset (header metadata and data).&amp;nbsp; That is a job for the DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If by tiny chance your goal is to write a function-style macro that would add variables to a dataset, that would be possible (using DOSUBL) but it would still use a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 18:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889233#M43466</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-14T18:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a new variable into an existing dataset using metadata function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889245#M43467</link>
      <description>&lt;P&gt;Adding a variable changes the observation length; since observations always occupy a contiguous space, the dataset needs to be rewritten.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 19:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889245#M43467</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-14T19:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a new variable into an existing dataset using metadata function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889248#M43468</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has stated, anytime you add or drop columns from a SAS dataset, you need to add or remove the space to hold it even if it contains only missing values. Changing just the descriptor portion of a SAS dataset is not possible when it involves adding or dropping columns.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 19:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-add-a-new-variable-into-an-existing-dataset-using/m-p/889248#M43468</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-08-14T19:57:23Z</dc:date>
    </item>
  </channel>
</rss>

