<?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 transpose, rename and fill a table when columns are identical? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724979#M225117</link>
    <description>Thanks Tom!!! You saved my day with this really simple solution... why am I thinking so hard... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
    <pubDate>Tue, 09 Mar 2021 20:48:59 GMT</pubDate>
    <dc:creator>SAS_Question</dc:creator>
    <dc:date>2021-03-09T20:48:59Z</dc:date>
    <item>
      <title>How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724931#M225094</link>
      <description>&lt;UL&gt;
&lt;LI&gt;I use SAS EG 7.1 version 9.4M2&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I have this data set in csv: have.csv (see attached)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I want this as result I want t achieve:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="What i want to achieve" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55740i6BDD31367708C2A7/image-size/large?v=v2&amp;amp;px=999" role="button" title="want.png" alt="What i want to achieve" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;What i want to achieve&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But i'm not there yet.. almost...&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;This is my SAS code so far:&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Datasets Lib=Work memtype=Data Kill nolist;
Quit;

options validvarname = V7; 

%let resp =P:\TEMP\;
%let resf =have.csv;

PROC IMPORT 
	datafile="&amp;amp;resp.&amp;amp;resf"
  	out=RES dbms=dlm replace;
  	delimiter=';';   
	getnames=yes; 
	guessingrows=MAX;
	datarow=2;
run;

PROC SQL;
	CREATE table WORK.tempTable AS
		SELECT distinct *
	FROM WORK.RES as T
;
QUIT;

proc sort data=work.tempTable; by NBR ID; run; 

data tries;
   set tempTable;
   BY NBR id;
   if FIRST.ID then
		tries = 0;
		tries + 1;
run;

proc sort data=work.tries; by id tries; run;
 
PROC TRANSPOSE DATA=WORK.TRIES
	OUT=WORK.TRANSPOSED(LABEL="Transposed")
	PREFIX=v 
	DELIMITER=_ 
	NAME=Source
	LABEL=Label 
	LET
;
	BY ID tries;
	ID NBR DESCR1;
	VAR GRADE;
RUN; QUIT;

/* how to change this proc transpose so it gives me what I want like in screenshot? */


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can some one please help me with the correct result?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TiA!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 18:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724931#M225094</guid>
      <dc:creator>SAS_Question</dc:creator>
      <dc:date>2021-03-09T18:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724943#M225100</link>
      <description>&lt;P&gt;First thing, if you want a process repeatable with a different data file do not use proc import. There is not guarantee that your variable types or lengths will stay the same. Write a data step and take control of your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, your picture shows column headings that would not be standard SAS variable names. So are those supposed to be the names of the variables or a label for the heading?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third, there really isn't any 'nice' way to have "first" "second" "third" and "fourth" in a sequential name, the digits would be better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want those "headings" I suggest creating heading in the data state as a separate variable and use that as an IDLABEL. You may want a custom format to display 1 as "first' , 2 as 'second' and so on. You could then use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;labelvar = catx('_',id,put(try, tryformat.),'try');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;make sure to assign a length long enough to hold the longest expected combination.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 18:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724943#M225100</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-09T18:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724958#M225105</link>
      <description>Thank you for the reply &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;BR /&gt;1) I must use import, because the real csv is really big:more than 1 million rows... so, i can't write a data step &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;2) I came across that myself too... you can't let a name for a sas variable begin with a number. True! As you can see in my code I already solved that with: PREFIX=v in Proc Transpose. So you get: v11111111111_ etc. &lt;BR /&gt;3) The names were just an idea. You may name it whatever you want! As long as the result is clear... what I want. So it can also be 1, 2 and 3 yes of course! &lt;BR /&gt;</description>
      <pubDate>Tue, 09 Mar 2021 19:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724958#M225105</guid>
      <dc:creator>SAS_Question</dc:creator>
      <dc:date>2021-03-09T19:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724970#M225111</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/195211"&gt;@SAS_Question&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;...&lt;BR /&gt;1) I must use import, because the real csv is really big:more than 1 million rows... so, i can't write a data step &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;BR /&gt;...&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That statement makes no sense. The complexity of the data step is related to the number of variables, not the number of observations.&amp;nbsp; Your posted example only has 5 variables.&amp;nbsp;&amp;nbsp;All you need to do is decide how you want to define those variables and you can do a much better job of making that decision that PROC IMPORT could ever hope to do.&amp;nbsp; The data step code is shorter than the PROC IMPORT code it replaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data RES ;
  infile "&amp;amp;resp.&amp;amp;resf" dsd dlm=';' firstobs=2 truncover ;
  input ID NBR :$20. DESCR1 :$8. DATE :ddmmyy. GRADE&amp;nbsp;;
  format date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 20:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724970#M225111</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-09T20:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724973#M225114</link>
      <description>&lt;P&gt;What are you going to do with that dataset once you create it?&amp;nbsp; That structure does not look very useful for anything.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 20:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724973#M225114</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-09T20:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724976#M225115</link>
      <description>&lt;P&gt;Seems pretty straight forward.&lt;/P&gt;
&lt;P&gt;Read the data. Sort. Add the TRY counter so you can generate unique names. And transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your GRADE variable appears to be mainly numeric but has some observations with values like 'O' and 'V'.&amp;nbsp; You can use the missing option to tell SAS to read those as special missing values of .O and .V.&amp;nbsp; Or you could read GRADE as character variable.&amp;nbsp; Whether GRADE is numeric or character does not cahnge the transposing logic, just the type of variables that end up being generated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;missing o v ;

data RES ;
  infile "c:\downloads\have.csv" dsd dlm=';' firstobs=2 truncover ;
  input ID NBR :$20. DESCRIPTION :$8. DATE :ddmmyy. GRADE ;
  format date yymmdd10.;
run;

proc sort data=res;
  by id nbr description date ;
run;

data for_transpose ;
  set res;
  by id nbr description;
  try+1;
  if first.description then try=1;
run;

proc transpose data=for_transpose 
  out=want(drop=_name_)
  prefix=NBR_
  delim=_
;
  by id;
  id nbr description try;
  var grade ;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;         NBR_00000000P_ NBR_00000000P_ NBR_11111111T_ NBR_22222222S_ NBR_22222222S_ NBR_11111111T_
Obs  ID       BP_1           BP_2           BR_1           BS_1           BS_2           BR_2

 1  2887        4              7              6              O              V              .
 2  2888        7              .              9              V              .              .
 3  2889        9              .              5              V              .              6

&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Mar 2021 20:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724976#M225115</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-09T20:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724977#M225116</link>
      <description>&lt;P&gt;Yes you are right. And so is Ballardw. Sorry. I misunderstood his advice!&lt;/P&gt;
&lt;P&gt;I thought he meant making a data set like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
infile datalines expandtabs;
input (STUDENT_ID COURSE_ID) ($) GRADE_POINTS EXAM_DATE :yymmdd10.;
format EXAM_DATE yymmdd10.;
datalines;
1111 1000T 6 2017-07-05
1111 2000T 7 2017-10-31
2222 1000T 8 2017-10-30
2222 2000T 8 2017-01-10
2222 3000T 8 2017-01-05
2222 4000T 9 2017-03-22
2222 5000T 9 2017-03-20
2222 6000T 8 2017-05-29
2222 7000T 9 2017-06-06
2222 8000T 7 2017-05-31
3333 4000T 9 2015-10-26
4444 1000T 7.5 2015-10-09
4444 2000T 8 2015-10-06
4444 3000T 7 2016-11-23
4444 4000T 7 2015-11-19
4444 5000T 7.5 2015-12-14
4444 6000T 6 2017-03-02
4444 7000T 7 2016-06-10
4444 8000T 6 2016-04-14
4444 8000T 8 2016-05-14
;&lt;/PRE&gt;
&lt;P&gt;But he meant only this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;infile datalines expandtabs;
input (STUDENT_ID COURSE_ID) ($) GRADE_POINTS EXAM_DATE :yymmdd10.;
format EXAM_DATE yymmdd10.;
&lt;/PRE&gt;
&lt;P&gt;without data lines.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;And what the output will be used for... it is for concatenating it with other data of these students and seeing how a student is preforming in a particular group.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But all I know is, I need to deliver it like that example &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 20:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724977#M225116</guid>
      <dc:creator>SAS_Question</dc:creator>
      <dc:date>2021-03-09T20:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724979#M225117</link>
      <description>Thanks Tom!!! You saved my day with this really simple solution... why am I thinking so hard... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Tue, 09 Mar 2021 20:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724979#M225117</guid>
      <dc:creator>SAS_Question</dc:creator>
      <dc:date>2021-03-09T20:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose, rename and fill a table when columns are identical?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724993#M225122</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/195211"&gt;@SAS_Question&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes you are right. And so is Ballardw. Sorry. I misunderstood his advice!&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Juola's Metatheorem: You will seldom misunderstand a problem so as to make it simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dr. Juola was my first professor for statistics.&lt;/P&gt;
&lt;P&gt;I call this a metatheorem because it has applied to carpentry, car repairs, sewing and other projects besides statistics or math.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 22:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-rename-and-fill-a-table-when-columns-are/m-p/724993#M225122</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-09T22:01:03Z</dc:date>
    </item>
  </channel>
</rss>

