<?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: Creating SAS dataset with variable containing text string values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-dataset-with-variable-containing-text-string-values/m-p/854158#M337574</link>
    <description>&lt;P&gt;If you want to have embedded spaces (actually embedded delimiters) then you have three options.&lt;/P&gt;
&lt;P&gt;1) Use fixed length fields.&lt;/P&gt;
&lt;P&gt;2) Use the &amp;amp; modifier.&amp;nbsp; That will require two delimiters to mark the start of the next field.&lt;/P&gt;
&lt;P&gt;3) Use DSD option.&amp;nbsp; That will allow you use quotes the protected delimiters in the value.&amp;nbsp; But you cannot have more than one delimiter between the fields.&lt;/P&gt;
&lt;P&gt;4) Use the DLMSTR= option on the INFILE statement to specify a multiple byte delimiter string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data columns;
  infile datalines truncover;
  input order 1 var_name $ 2-14 Dimension $15-35 ;
*---+----1----+----2----+----3----+----0 ;
datalines;
1agegrp1      Age Group: &amp;lt;= 74
2agegrp2      Age Group: 75-79
3agegrp3      Age Group: 80-84
4agegrp4      Age Group: 85-89
5agegrp5      Age Group: 90+
6gender_f1    Female
;
data fixed;
  infile datalines truncover;
  input order 1. var_name $13. Dimension $21.;
*---+----1----+----2----+----3----+----0 ;
datalines;
1agegrp1      Age Group: &amp;lt;= 74
2agegrp2      Age Group: 75-79
3agegrp3      Age Group: 80-84
4agegrp4      Age Group: 85-89
5agegrp5      Age Group: 90+
6gender_f1    Female
;

data ampersand;
  input order var_name :&amp;amp;$13. Dimension &amp;amp;$21.;
*---+----1----+----2----+----3----+----0 ;
datalines;
1  agegrp1  Age Group: &amp;lt;= 74
2  agegrp2  Age Group: 75-79
3  agegrp3  Age Group: 80-84
4  agegrp4  Age Group: 85-89
5  agegrp5  Age Group: 90+
6  gender_f1  Female
;

data dsd;
  infile datalines dsd dlm='|' truncover;
  length order 8 var_name $13 Dimension $21 ;
  input order var_name Dimension ;
*---+----1----+----2----+----3----+----0 ;
datalines;
1|agegrp1|Age Group: &amp;lt;= 74
2|agegrp2|Age Group: 75-79
3|agegrp3|Age Group: 80-84
4|agegrp4|Age Group: 85-89
5|agegrp5|Age Group: 90+
6|gender_f1|Female
;
data dlmstr;
  infile datalines dlmstr='|x|' truncover;
  length order var_name $13 Dimension $21 ;
  input order var_name Dimension ;
*---+----1----+----2----+----3----+----0 ;
datalines;
1|x|agegrp1|x|Age Group: &amp;lt;= 74
2|x|agegrp2|x|Age Group: 75-79
3|x|agegrp3|x|Age Group: 80-84
4|x|agegrp4|x|Age Group: 85-89
5|x|agegrp5|x|Age Group: 90+
6|x|gender_f1|x|Female
;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Do not embed TAB characters in data (or programs for that matter) and definitely not in quoted string. They are too easily misunderstood by programmers and the programs you use to edit the file.&amp;nbsp; In code you can use the hex literal '09'x&amp;nbsp;to specify a TAB character.&lt;/P&gt;
&lt;P&gt;PS There is no need to include decimal places when specifying a LENGTH.&amp;nbsp; SAS can only store variables using whole numbers of bytes so you only need integer values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jan 2023 18:23:34 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-17T18:23:34Z</dc:date>
    <item>
      <title>Creating SAS dataset with variable containing text string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-dataset-with-variable-containing-text-string-values/m-p/854152#M337572</link>
      <description>&lt;P&gt;I'm trying to run the following code that creates a data table with a text string for the Dimension variable, however the variable values in the bal_cat dataset are all blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data bal_cat;
infile datalines delimiter='     '  truncover dsd;
length order 8.0 var_name $ 50;
length Dimension $ 200 ;
input order     var_name :$     Dimension :$ ;
datalines;
1    agegrp1    "Age Group: &amp;lt;= 74"
2    agegrp2    "Age Group: 75-79"
3    agegrp3    "Age Group: 80-84"
4    agegrp4    "Age Group: 85-89"
5    agegrp5    "Age Group: 90+"
6    gender_f1  "Female"
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jan 2023 17:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-dataset-with-variable-containing-text-string-values/m-p/854152#M337572</guid>
      <dc:creator>RobertWF2</dc:creator>
      <dc:date>2023-01-17T17:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SAS dataset with variable containing text string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-dataset-with-variable-containing-text-string-values/m-p/854158#M337574</link>
      <description>&lt;P&gt;If you want to have embedded spaces (actually embedded delimiters) then you have three options.&lt;/P&gt;
&lt;P&gt;1) Use fixed length fields.&lt;/P&gt;
&lt;P&gt;2) Use the &amp;amp; modifier.&amp;nbsp; That will require two delimiters to mark the start of the next field.&lt;/P&gt;
&lt;P&gt;3) Use DSD option.&amp;nbsp; That will allow you use quotes the protected delimiters in the value.&amp;nbsp; But you cannot have more than one delimiter between the fields.&lt;/P&gt;
&lt;P&gt;4) Use the DLMSTR= option on the INFILE statement to specify a multiple byte delimiter string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data columns;
  infile datalines truncover;
  input order 1 var_name $ 2-14 Dimension $15-35 ;
*---+----1----+----2----+----3----+----0 ;
datalines;
1agegrp1      Age Group: &amp;lt;= 74
2agegrp2      Age Group: 75-79
3agegrp3      Age Group: 80-84
4agegrp4      Age Group: 85-89
5agegrp5      Age Group: 90+
6gender_f1    Female
;
data fixed;
  infile datalines truncover;
  input order 1. var_name $13. Dimension $21.;
*---+----1----+----2----+----3----+----0 ;
datalines;
1agegrp1      Age Group: &amp;lt;= 74
2agegrp2      Age Group: 75-79
3agegrp3      Age Group: 80-84
4agegrp4      Age Group: 85-89
5agegrp5      Age Group: 90+
6gender_f1    Female
;

data ampersand;
  input order var_name :&amp;amp;$13. Dimension &amp;amp;$21.;
*---+----1----+----2----+----3----+----0 ;
datalines;
1  agegrp1  Age Group: &amp;lt;= 74
2  agegrp2  Age Group: 75-79
3  agegrp3  Age Group: 80-84
4  agegrp4  Age Group: 85-89
5  agegrp5  Age Group: 90+
6  gender_f1  Female
;

data dsd;
  infile datalines dsd dlm='|' truncover;
  length order 8 var_name $13 Dimension $21 ;
  input order var_name Dimension ;
*---+----1----+----2----+----3----+----0 ;
datalines;
1|agegrp1|Age Group: &amp;lt;= 74
2|agegrp2|Age Group: 75-79
3|agegrp3|Age Group: 80-84
4|agegrp4|Age Group: 85-89
5|agegrp5|Age Group: 90+
6|gender_f1|Female
;
data dlmstr;
  infile datalines dlmstr='|x|' truncover;
  length order var_name $13 Dimension $21 ;
  input order var_name Dimension ;
*---+----1----+----2----+----3----+----0 ;
datalines;
1|x|agegrp1|x|Age Group: &amp;lt;= 74
2|x|agegrp2|x|Age Group: 75-79
3|x|agegrp3|x|Age Group: 80-84
4|x|agegrp4|x|Age Group: 85-89
5|x|agegrp5|x|Age Group: 90+
6|x|gender_f1|x|Female
;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Do not embed TAB characters in data (or programs for that matter) and definitely not in quoted string. They are too easily misunderstood by programmers and the programs you use to edit the file.&amp;nbsp; In code you can use the hex literal '09'x&amp;nbsp;to specify a TAB character.&lt;/P&gt;
&lt;P&gt;PS There is no need to include decimal places when specifying a LENGTH.&amp;nbsp; SAS can only store variables using whole numbers of bytes so you only need integer values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2023 18:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-dataset-with-variable-containing-text-string-values/m-p/854158#M337574</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-17T18:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SAS dataset with variable containing text string values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-dataset-with-variable-containing-text-string-values/m-p/854164#M337576</link>
      <description>Thanks Tom! That solved it!</description>
      <pubDate>Tue, 17 Jan 2023 18:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-SAS-dataset-with-variable-containing-text-string-values/m-p/854164#M337576</guid>
      <dc:creator>RobertWF2</dc:creator>
      <dc:date>2023-01-17T18:05:42Z</dc:date>
    </item>
  </channel>
</rss>

