<?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 new row with dynamic data in existing SAS data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586603#M167465</link>
    <description>&lt;P&gt;Amazing. Thanks a lot. Just a small related question, how would I do the same thing in the column type is Numeric with informat is 'DATETIME21'?&lt;/P&gt;</description>
    <pubDate>Fri, 06 Sep 2019 02:43:00 GMT</pubDate>
    <dc:creator>Gagan_s</dc:creator>
    <dc:date>2019-09-06T02:43:00Z</dc:date>
    <item>
      <title>How to add new row with dynamic data in existing SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586318#M167372</link>
      <description>&lt;P&gt;I need to insert a new row into an existing SAS data set. Data set has column as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Name		Type
Id		Numeric&lt;/PRE&gt;&lt;P&gt;Data that I want to insert (as a new row) is dynamic. Hence I want my solution to accept the data at run time and then insert as a new row into the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did some search and came to know that I can set some environment variable at run time and then my SAS program can read those value to insert into the SAS data set. I did something like this:&lt;/P&gt;&lt;PRE&gt;export Id_VAL=5&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
  insert into LibName.dataset values (
	input(sysget('Id_VAL'),best.), 
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;However upon running the above code I am getting:&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;38         	input(sysget('Id_VAL'),best.),
            _____
            22
            76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, 
              a missing value, +, -, MISSING, NULL, USER.  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;I also checked on creating another data set and then merging with the main data set using proc append command but not sure how I can pass values at run time.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;I am a newbie in SAS hence I am not sure if this is the right solution.&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS version 9.4&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 06:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586318#M167372</guid>
      <dc:creator>Gagan_s</dc:creator>
      <dc:date>2019-09-05T06:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new row with dynamic data in existing SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586325#M167373</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288440"&gt;@Gagan_s&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are almost there. I used a couple of existing environment variables in the following examples:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;****** Test with numeric value ****;
* Initiate data set;
data ds; 
	PROCESSOR_LEVEL = 1; 
run;

* Add value of numeric environment variable;
proc SQL;
  insert into ds values (%sysfunc(sysget(PROCESSOR_LEVEL)));
quit;

****** Same test with character value ****;
* Initiate data set;
data ds; 
	USERDOMAIN = 'kfhadjkhajkdfhasdkfhahk'; 
run;

* Add value of character environment variable - note use of quotes;
proc SQL;
  insert into ds values ("%sysfunc(sysget(USERDOMAIN))");
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 07:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586325#M167373</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-09-05T07:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new row with dynamic data in existing SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586566#M167441</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288440"&gt;@Gagan_s&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You can keep your input/sysget syntax, but then you have to add the record in the DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data libname.dataset ;                                                                                                                                                                                                                                          
  id = input (sysget ("id_val"), best.) ;                                                                                                                                                                                                                       
  output ;                                                                                                                                                                                                                                                      
  stop ;                                                                                                                                                                                                                                                        
  modify libname.dataset ;                                                                                                                                                                                                                                      
run ;                     
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, you can do it this way (&lt;EM&gt;not recommended&lt;/EM&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data libname.dataset ;      
  set libname.dataset end = z ;  &lt;BR /&gt;  output ;     
  if z ;                                                                                                                                                                                                                             
  id = input (sysget ("id_val"), best.) ;                                                                                                                                                                                                                       
  output ;                                                                                                                                                                                                                 
run ;    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, this code rereads the entire data set and then rewrites it with 1 observation added. By contrast, the step with MODIFY just adds the new record to the existing data set without reading any observations in - essentially just the way proc APPEND does. Speaking of which, you can of course use it as an alternative:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new ;
  id = input (sysget ("id_val"), best.) ;
run ;

proc append base = libname.dataset data = new ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 22:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586566#M167441</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-05T22:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new row with dynamic data in existing SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586603#M167465</link>
      <description>&lt;P&gt;Amazing. Thanks a lot. Just a small related question, how would I do the same thing in the column type is Numeric with informat is 'DATETIME21'?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 02:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586603#M167465</guid>
      <dc:creator>Gagan_s</dc:creator>
      <dc:date>2019-09-06T02:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new row with dynamic data in existing SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586633#M167473</link>
      <description>&lt;P&gt;found the solution for inserting&amp;nbsp;DATETIME21 date in existing stored proc (reading value from env variable)&lt;/P&gt;&lt;PRE&gt;export PROCESS_DTTM=\'07AUG2019:15:04:53\'dt&lt;/PRE&gt;&lt;P&gt;and then inserting the data in stored proc like:&lt;/P&gt;&lt;PRE&gt;%sysfunc(sysget(PROCESS_DTTM))&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2019 06:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586633#M167473</guid>
      <dc:creator>Gagan_s</dc:creator>
      <dc:date>2019-09-06T06:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to add new row with dynamic data in existing SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586659#M167478</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288440"&gt;@Gagan_s&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Time is 9.53 here, and I'm busy at work right now, but I will look into it later today.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would you please post an example of an actual value?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 07:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-new-row-with-dynamic-data-in-existing-SAS-data-set/m-p/586659#M167478</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-09-06T07:57:35Z</dc:date>
    </item>
  </channel>
</rss>

