| Date: | Mon, 12 Oct 2009 12:34:05 -0500 |
| Reply-To: | Joe Matise <snoopy369@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Joe Matise <snoopy369@GMAIL.COM> |
| Subject: | Re: Proc Transpose |
|
| In-Reply-To: | <4AD32CAE020000E20002F110@mailsrv4.gsu.edu> |
| Content-Type: | text/plain; charset=ISO-8859-1 |
|---|
First off, your PROC FORMAT needs to end with a QUIT; statement. Even when
it's not needed [say, two data steps after each other], it's much, much
neater to code all steps as starting with PROC/DATA/whatever and ending with
QUIT/RUN as appropriate. Easier to read, and sometimes it does matter.
Second, why are you not applying the format in the initial datastep?
Third, you might want to just read this in as one step, no transpose. Why
not do:
data P405;
format question $qfmt.;
infile io (_p405.yyy) missover;
input @41 code 3. @46 Job 1. @;
do _t = 52 to length(_infile_);
question=substr(_infile_,_t,1);
put question=;
output;
end;
drop _t;
run;
or something like that (I like to use the _infile_ buffer instead of
inputting, as I make fewer mistakes that way, but you may prefer the
reverse). Does that give you what you want (many records per job/code, one
question answer per record, formatted with your custom format)?
-Joe
On Mon, Oct 12, 2009 at 12:18 PM, Carol Thurman <erbcjt@langate.gsu.edu>wrote:
> Hi All,
>
> I would like to get my data so that the string of A's, B's etc go down the
> columns rather than across. I have written code but when I print the
> output, it doesn't look correct. Can someone help me out, please?
>
> I have copied the first line of a text file below ( so you can refer to
> it). The data doesn't start until after the N. After
> the N, the first 3 digits are the school code followed by 001 or 002
> indicating whether or not the respondent is classified staff or
> non-classified staff.
>
> Thanks,
>
> Carol
>
> N 405001
>
> ABBBBBBBAABBBBABBBAABBBBBBAAAABBAAAAAAAABBBBBBBBBAAAAAAAAAAAABBBBBBBBBBBBBBBBB
>
>
> THIS IS MY CODE:
>
> filename io 'E:\PAL 2009';
>
> proc format;
> value $qfmt A='SA' B='A' C='D' D='SD' E='NA';
> data P405;
> infile io (_p405.yyy) missover;
> input @41 code 3. @46 Job 1. @52 (q1-q78) ($1.);
> proc sort data = P405;
> by Job;
>
> proc transpose data=P405 OUT= P405T;
> by job;
>
> VAR q1-q78;
>
> format q1-q78 $qfmt.;
> proc print data=P405T;
> run;
>
|