<?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 reshape multiple variables with different suffix? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908460#M40633</link>
    <description>&lt;P&gt;You didn't provide sample data in the form of a working data step, so this program isn't (fully) tested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_: rcid_: frcid_:);
  id=_n_;
  length source $5;
  set have;
  by gvkey year;
  retain      _cik 'cik  '  _cusip 'cusip'  _gvkey 'gvkey' ;
  array  src  _cik          _cusip          _gvkey ;

  array rcid_data   rcid_cik   rcid_cusip   rcid_gvkey ;
  array frcid_data  frcid_cik  frcid_cusip  frcid_gvkey ;

  do over src;
    source=src;
    rcid=rcid_data;
    frcid=frcid_data;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 16 Dec 2023 03:59:27 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-12-16T03:59:27Z</dc:date>
    <item>
      <title>How to reshape multiple variables with different suffix?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908449#M40627</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to reshape a table in sas.&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;I have column called gvkey, fyear, each gvkey-fyear is an identifier (unique). I have other columns called rcid_gvkey, rcid_cusip, rcid_cik, frcid_gvkey, frcid_cusip, frcid_gvkey.&lt;/DIV&gt;&lt;DIV&gt;How can I reshape it to have one rcid column with rcid_gvkey, rcid_cusip, rcid_cik of the same observation (gvkey-year) in different rows, and a new column called rcid_source indicates the sources(so if it is rcid_gvkey, it should have "gvkey" as the value of this column). I also want one column called frcid with frcid_gvkey, frcid_cusip, frcid_gvkey of the same observations in different rows, and a new column called frcid_source indicating the sources.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I attach a simple example below (should also have frcid_gvkey, frcid_cusip, frcid_cik columns, but to keep it simple I did not generate the sample)&lt;/DIV&gt;&lt;DIV&gt;I try the following but it does not work...&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;proc transpose data=temp.comp_rcid out=temp.comp_rcid_rshp&amp;nbsp;
(rename=(col1=rcid_source col2=frcid_source));
&amp;nbsp; by gvkey fyear;
&amp;nbsp; var rcid_gvkey rcid_cusip rcid_cik frcid_gvkey frcid_cusip frcid_cik;
run;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Can you help me ? thank you!&lt;/DIV&gt;</description>
      <pubDate>Sat, 16 Dec 2023 01:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908449#M40627</guid>
      <dc:creator>Eileen1496</dc:creator>
      <dc:date>2023-12-16T01:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape multiple variables with different suffix?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908450#M40628</link>
      <description>If you only have a few, a data step with explicit output statements is a better approach. If you have more then this process could be more automated with arrays and macros.</description>
      <pubDate>Fri, 15 Dec 2023 23:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908450#M40628</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-12-15T23:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape multiple variables with different suffix?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908451#M40629</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp.comp_rcid_rshp;
set temp.comp_rcid;
keep gvkey fyear cusip cik;
length source $12.;
source = 'original';
output;
source = 'rcid';
gvkey = rcid_gvkey;
cusip = rcid_cusip;
cik = rcid_cik;
output;
source = 'frcid';
gvkey = frcid_gvkey;
cusip = frcid_cusip;
cik = frcid_cik;
output;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Something along the lines above, assuming I somewhat understand your data (hard without seeing an example)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/446510"&gt;@Eileen1496&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I'm trying to reshape a table in sas.&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;I have column called gvkey, fyear, each gvkey-fyear is an identifier (unique). I have other columns called rcid_gvkey, rcid_cusip, rcid_cik, frcid_gvkey, frcid_cusip, frcid_gvkey.&lt;/DIV&gt;
&lt;DIV&gt;How can I reshape it to have one rcid column with rcid_gvkey, rcid_cusip, rcid_cik of the same observation (gvkey-year) in different rows, and a new column called rcid_source indicates the sources(so if it is rcid_gvkey, it should have "gvkey" as the value of this column). I also want one column called frcid with frcid_gvkey, frcid_cusip, frcid_gvkey of the same observations in different rows, and a new column called frcid_source indicating the sources.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I try the following but it does not work...&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;proc transpose data=temp.comp_rcid out=temp.comp_rcid_rshp&amp;nbsp;
(rename=(col1=rcid_source col2=frcid_source));
&amp;nbsp; by gvkey fyear;
&amp;nbsp; var rcid_gvkey rcid_cusip rcid_cik frcid_gvkey frcid_cusip frcid_cik;
run;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Can you help me ? thank you!&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 23:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908451#M40629</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-12-15T23:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape multiple variables with different suffix?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908456#M40631</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply. This is not what I mean. I just uploaded an excel with example, could you help me see again? I really appreciate it.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2023 01:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908456#M40631</guid>
      <dc:creator>Eileen1496</dc:creator>
      <dc:date>2023-12-16T01:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape multiple variables with different suffix?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908457#M40632</link>
      <description>&lt;P&gt;Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2023 01:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908457#M40632</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-16T01:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to reshape multiple variables with different suffix?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908460#M40633</link>
      <description>&lt;P&gt;You didn't provide sample data in the form of a working data step, so this program isn't (fully) tested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_: rcid_: frcid_:);
  id=_n_;
  length source $5;
  set have;
  by gvkey year;
  retain      _cik 'cik  '  _cusip 'cusip'  _gvkey 'gvkey' ;
  array  src  _cik          _cusip          _gvkey ;

  array rcid_data   rcid_cik   rcid_cusip   rcid_gvkey ;
  array frcid_data  frcid_cik  frcid_cusip  frcid_gvkey ;

  do over src;
    source=src;
    rcid=rcid_data;
    frcid=frcid_data;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Dec 2023 03:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reshape-multiple-variables-with-different-suffix/m-p/908460#M40633</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-12-16T03:59:27Z</dc:date>
    </item>
  </channel>
</rss>

