LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 10 Sep 2010 22:13:53 -0400
Reply-To:     Ya Huang <ya.huang@AMYLIN.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ya Huang <ya.huang@AMYLIN.COM>
Subject:      Re: Transform text, maybe an array needed,
              needs to output to text file
Comments: To: Andy Sasuser <sas9bi@GMAIL.COM>

Here is the one:

proc sort; by group; run;

data _null_; set have end=end; by group; if first.group then put "Case When table.abcfield IN (" @; if not last.group then put id +(-1) ',' @; if last.group then put id ") then '" group +(-1) "'"; if end then put "else 'Unknown' end"; run;

Case When table.abcfield IN (123,456,654 ) then 'Data 01' Case When table.abcfield IN (789 ) then 'Data 02' Case When table.abcfield IN (987 ) then 'Data 03' else 'Unknown' end

Just add the file statement.

HTH

Ya

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;


Back to: Top of message | Previous page | Main SAS-L page