Date: Mon, 13 Sep 2010 01:35:08 -0400
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: Transform text, maybe an array needed,
needs to output to text file
Content-Type: text/plain; charset=ISO-8859-1
You can accomplish what you want (an SQL CASE statement that translates
ID to group) in an even simpler way, like this:
data _null_;
file "c:\temp\want.txt";
set have end=done;
if _n_=1 then
put "CASE table.abcfield";
put "WHEN " ID "THEN '" group +(-1) "'";
if done then
put "ELSE 'UNKNOWN'"/
"END";
run;
Probably runs just as fast as the version with the IN-clauses, and you
do not have to sort your data (unless they contain duplicate IDs).
Regards,
Søren
On Fri, 10 Sep 2010 20:55:57 -0500, sas 9 bi user <sas9bi@GMAIL.COM> wrote:
>/*
>All
>
>I have been on other projects not SAS related for years now, so forgive my
>lack of SAS vernacular in how I worded my question below.
>
>I have a hopefully easy question, I have some data below that looks like my
>'have" dataset below. In reality it has 1000's of records with a unique ID
>(example below), I want some quick SAS datastep to take my "have" below,
and
>make it look like the output of the file "want.txt" (see data _null_ below)
>and formatted exactly as shown (except I would like it automated). Does
>that makes logical sense? I am trying to use SAS to build a CASE statement
>with data I already have and output it as a text file to be used elsewhere.
>
>Thus, thanks in advance for any advice, hope all of you are doing well.
>Best!!
>*/
>
>data have;
>input group $1-7 ID;
>datalines;
>Data 01 123
>Data 01 456
>Data 02 789
>Data 03 987
>Data 01 654
>;
>run;
>
>/* I not sure how to create a middle step that would output a file that
>would look like my want.txt below?*/
>
>data _null_;
>file "c:\temp\want.txt";
>put "CASE";
>put "WHEN table.abcfield IN";
>put "(123,456,654)";
>put "THEN 'Data 01'";
>put "WHEN table.abcfield IN";
>put "(789)";
>put "THEN 'Data 02'";
>put "WHEN table.abcfield IN";
>put "(987)";
>put "THEN 'Date 03'";
>put "ELSE 'Unknown'";
>put "END";
>run;
|