Date: Mon, 8 May 2006 16:45:49 -0500
Reply-To: Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Subject: Re: Challenging SAS unstructed data input problem
Content-Type: text/plain; charset=US-ASCII
Try the following and the text output in "C:\TabResult" follows the
code.
data _null_;
length result $ 256;
infile "C:\CommaSpace" dsd;
file "C:\TabResult";
input;
result=" ";
if _N_ eq 1 then do;
CommaCount=countc(_infile_,",");
do i=1 to CommaCount+1;
if i le CommaCount then
result=compress(result) || quote(scan(_infile_,i)) || '09'x;
else
result=compress(result) || quote(scan(_infile_,i));
end;
put result;
end;
else do;
QuoteCount=countc(_infile_,'"');
do i=1 to QuoteCount-1 by 2;
if i lt QuoteCount-1 then
result=compress(result) || quote(scan(_infile_,i,'"')) ||
'09'x;
else
result=compress(result) || quote(scan(_infile_,i,'"'));
end;
put result;
end;
run;
***** "C:\TabResult" content *****
"COUNTRYID" "PANEL" "TIME_PERIOD" "DOMAIN_NAME" "CATEGORY" "SUBCATEGORY_NAME" "UA_000" "PV_000" "COMPPCT_UA" "COMPIDX_UA" "COVERAGE"
"US" "Combo" "Q103" "yahoo.com" "1.ALL" "Total" "110447" "54869418" "100" "100" "74.17"
"US" "Combo" "Q103" "yahoo.com" "2.GENDER" "MALE" "55219" "31487544" "50" "101" "74.85"
"US" "Combo" "Q103" "yahoo.com" "2.GENDER" "FEMALE" "55228" "23381875" "50" "99" "73.5"
"US" "Combo" "Q103" "yahoo.com" "2.GENDER" "FEMALE" "55228" "23381875" "50" "99" "73.5"
J S Huang
1-515-557-3987
fax 1-515-557-2422
>>> <denisu.pong@GMAIL.COM> 05/08/06 2:53 PM >>>
hi,
I'm trying to reformat the data to make it easily import-able by proc
import later on. Here is a sample of my .dat file - header is space
and
comma separated, whereas the data is tab-delimited.
COUNTRYID, PANEL, TIME_PERIOD, DOMAIN_NAME, CATEGORY,
SUBCATEGORY_NAME,
UA_000, PV_000, COMPPCT
_UA, COMPIDX_UA, COVERAGE
"US" "Combo" "Q103" "yahoo.com" " 1. ALL" "Total" "110447
" "54869418" "100" "100" "74.17"
"US" "Combo" "Q103" "yahoo.com" " 2. GENDER" "MALE"
"55219"
"31487544" "50"
"101" "74.85"
"US" "Combo" "Q103" "yahoo.com" " 2. GENDER" "FEMALE"
"55228" "23381875"
"50" "99" "73.5"
"US" "Combo" "Q103" "yahoo.com" " 2. GENDER" "FEMALE"
"55228" "23381875"
"50" "99" "73.5"
And here is what I wanted it to become eventually - Nice, clean
tab-delimited file.
"COUNTRYID" "PANEL" "TIME_PERIOD" "DOMAIN_NAME" "CATEGORY"
"SUBCATEGORY_NAME" "UA_000" "PV_000" "COMPPCT_UA"
"COMPIDX_UA" "COVERAGE"
"US" "Combo" "Q103" "yahoo.com" " 1. ALL" "Total"
"110447"
"54869418" "100" "100" "74.17"
Any help is appreciated~!