<?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 How to write all variable name followed by value in quotes while writing a text file from a dataset? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608165#M17639</link>
    <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TableA&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Col1&amp;nbsp; &amp;nbsp;Col2&lt;/U&gt;&lt;/P&gt;&lt;P&gt;abc&amp;nbsp; &amp;nbsp; &amp;nbsp;123&lt;/P&gt;&lt;P&gt;abd&amp;nbsp; &amp;nbsp; &amp;nbsp; 90&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;&lt;STRONG&gt;I want to write file like this:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;Col1="abc" Col2="123"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;Col1="abd" Col2="90"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I &lt;FONT color="#FF0000"&gt;don't&lt;/FONT&gt; want to name the variables like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Put 'Col1=' col1 ~ 'Col2=' col2 ~ ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It should print all variables in a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This &lt;FONT color="#000000"&gt;doesn't work&lt;/FONT&gt; as it puts &lt;FONT color="#FF0000"&gt;only values in quotes:&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Put (_ALL_) (~) ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This puts all variable names and values &lt;FONT color="#FF0000"&gt;without quotes&lt;/FONT&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Put (_ALL_) (=);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to combine above two ways or is there any other way to do this?&lt;/P&gt;&lt;P&gt;I am using Base SAS9.4 on windows server 2008 R2&lt;/P&gt;</description>
    <pubDate>Fri, 29 Nov 2019 04:57:44 GMT</pubDate>
    <dc:creator>kumarayas</dc:creator>
    <dc:date>2019-11-29T04:57:44Z</dc:date>
    <item>
      <title>How to write all variable name followed by value in quotes while writing a text file from a dataset?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608165#M17639</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TableA&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Col1&amp;nbsp; &amp;nbsp;Col2&lt;/U&gt;&lt;/P&gt;&lt;P&gt;abc&amp;nbsp; &amp;nbsp; &amp;nbsp;123&lt;/P&gt;&lt;P&gt;abd&amp;nbsp; &amp;nbsp; &amp;nbsp; 90&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;&lt;STRONG&gt;I want to write file like this:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;Col1="abc" Col2="123"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="terminal,monaco"&gt;Col1="abd" Col2="90"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I &lt;FONT color="#FF0000"&gt;don't&lt;/FONT&gt; want to name the variables like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Put 'Col1=' col1 ~ 'Col2=' col2 ~ ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It should print all variables in a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This &lt;FONT color="#000000"&gt;doesn't work&lt;/FONT&gt; as it puts &lt;FONT color="#FF0000"&gt;only values in quotes:&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Put (_ALL_) (~) ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This puts all variable names and values &lt;FONT color="#FF0000"&gt;without quotes&lt;/FONT&gt;:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Put (_ALL_) (=);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to combine above two ways or is there any other way to do this?&lt;/P&gt;&lt;P&gt;I am using Base SAS9.4 on windows server 2008 R2&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 04:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608165#M17639</guid>
      <dc:creator>kumarayas</dc:creator>
      <dc:date>2019-11-29T04:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to write all variable name followed by value in quotes while writing a text file from a data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608231#M17649</link>
      <description>&lt;P&gt;You could change it later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename x temp;
data _null_;
 set sashelp.class;
file x;
put (_all_) (=);
run;

filename want 'c:\temp\want.txt';
data x;
 infile x truncover ;
 input x $200.;
 y=prxchange('s/=?(=(\S+))/="\2"/',-1,x);
 file want ;
 put y;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Nov 2019 11:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608231#M17649</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-29T11:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to write all variable name followed by value in quotes while writing a text file from a data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608236#M17651</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro exportNamed(Table=,File=);
  %let Lib=%upcase(%scan(&amp;amp;Table,1,.));
  %let Tab=%upcase(%scan(&amp;amp;Table,2,.));
  %if %length(&amp;amp;Tab) = 0 %then %do;
    %let Tab=&amp;amp;Lib;
    %let Lib=WORK;
  %end;
  %let columns=;
  proc sql noprint;
    select name into : columns separated by '#'
    from dictionary.columns
    where libname = "&amp;amp;Lib"
      and memname = "&amp;amp;Tab" 
    order by npos;
  quit;

  filename outfile "&amp;amp;File";
  /* Export the values */
  data _null_;
    set &amp;amp;Table. ;
    file outfile;
    put
    %let _col=;
    %let i = 1;
    %do %until( %length(&amp;amp;_col)=0 );
      %let _col = %qscan(&amp;amp;columns,&amp;amp;i,#);
      %if %length(&amp;amp;_col) &amp;gt; 0 %then %do;
        "&amp;amp;_col.=" '"' &amp;amp;_col +(-1) '"' +1
      %end;
      %let i=%eval(&amp;amp;i + 1);
    %end;
      ;
  run;

  filename outfile clear;
%mend;

%ExportNamed(Table=sashelp.class,File=myfile.txt);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Age="14" Height="69" Weight="112.5" Name="Alfred" Sex="M"
Age="13" Height="56.5" Weight="84" Name="Alice" Sex="F"
Age="13" Height="65.3" Weight="98" Name="Barbara" Sex="F"
Age="14" Height="62.8" Weight="102.5" Name="Carol" Sex="F"
Age="14" Height="63.5" Weight="102.5" Name="Henry" Sex="M"
Age="12" Height="57.3" Weight="83" Name="James" Sex="M"
Age="12" Height="59.8" Weight="84.5" Name="Jane" Sex="F"
Age="15" Height="62.5" Weight="112.5" Name="Janet" Sex="F"
Age="13" Height="62.5" Weight="84" Name="Jeffrey" Sex="M"
Age="12" Height="59" Weight="99.5" Name="John" Sex="M"
Age="11" Height="51.3" Weight="50.5" Name="Joyce" Sex="F"
Age="14" Height="64.3" Weight="90" Name="Judy" Sex="F"
Age="12" Height="56.3" Weight="77" Name="Louise" Sex="F"
Age="15" Height="66.5" Weight="112" Name="Mary" Sex="F"
Age="16" Height="72" Weight="150" Name="Philip" Sex="M"
Age="12" Height="64.8" Weight="128" Name="Robert" Sex="M"
Age="15" Height="67" Weight="133" Name="Ronald" Sex="M"
Age="11" Height="57.5" Weight="85" Name="Thomas" Sex="M"
Age="15" Height="66.5" Weight="112" Name="William" Sex="M"&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Nov 2019 12:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608236#M17651</guid>
      <dc:creator>MichaelLarsen</dc:creator>
      <dc:date>2019-11-29T12:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to write all variable name followed by value in quotes while writing a text file from a data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608306#M17658</link>
      <description>&lt;P&gt;It is easy to do with character variables.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;678   data _null_;
679    set sashelp.class (obs=2);
680    format _character_ $quote. ;
681    put (_all_) (=);
682   run;

Name="Alfred" Sex="M" Age=14 Height=69 Weight=112.5
Name="Alice" Sex="F" Age=13 Height=56.5 Weight=84
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Why would you want quotes around numeric values?&amp;nbsp; Perhaps you can build your won QUOTE format for numeric variables using PROC FORMAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can use CALL VNEXT() to loop through the variable names and VVALUEX() to get the formatted values of the variables.&amp;nbsp; You will need to invent two new variable names that do not conflict with any of your existing variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you want to do with leading spaces in the displayed values? Here is code that removes them for numeric variables only.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsn=sashelp.class(obs=2);

data _null_;
 set &amp;amp;dsn ;
 length __name $32 __value $32767 ;
 do while (1=1);
   call vnext(__name);
   if __name = '__name' then leave;
   __value=vvaluex(__name);
   if vtypex(__name)='N' then __value=left(__value);
   put __name +(-1) '=' __value :$quote. @;
 end;
 put;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Name="Alfred" Sex="M" Age="14" Height="69" Weight="112.5"
Name="Alice" Sex="F" Age="13" Height="56.5" Weight="84"
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 19:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608306#M17658</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-29T19:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to write all variable name followed by value in quotes while writing a text file from a data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608615#M17710</link>
      <description>Thanks. It works really well.</description>
      <pubDate>Mon, 02 Dec 2019 04:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608615#M17710</guid>
      <dc:creator>kumarayas</dc:creator>
      <dc:date>2019-12-02T04:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to write all variable name followed by value in quotes while writing a text file from a data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608616#M17711</link>
      <description>It works but is quite slow for large datasets.</description>
      <pubDate>Mon, 02 Dec 2019 04:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-write-all-variable-name-followed-by-value-in-quotes-while/m-p/608616#M17711</guid>
      <dc:creator>kumarayas</dc:creator>
      <dc:date>2019-12-02T04:12:04Z</dc:date>
    </item>
  </channel>
</rss>

