Problem: I receive a file from outside client that is a extract from mysql dumped to text. As the database grows the format of the file is bound to alter based of the data input into the clients survey application. Because of the boundless nature of the input a dynamic fixed length reading step seems to be the most productionable way to convert this data. In other words - The input column will not change in any way from day-to-day however the length of the fields will change as data is collected (to be the length of the longest entity of the column). As you can see there are delimiters between the columns however there is no restriction to the data entered so the delimiter cannot be necesarily relied upon from a row-to-row basis. Desired Outcome: Properly converted sas data to later be utilized for reporting purposes. Obs list_name original_filename email_addr member jobno job_name ae question choice comment 1 08232011 survey_list_20110823.csv this_is@anemailaddress.com MEM1 FT93 This is a jobs name hjsimpson How satisfied were you with the accuracy of your order? 4 2 08232011 survey_list_20110823.csv this_is@anemailaddress.com MEM1 FT93 This is a jobs name hjsimpson How satisfied were you with the timeliness of your order? 3 This is some sort of random comment that the user has decided to leave in response to this question. 3 08232011 survey_list_20110823.csv this_is@anemailaddress.com MEM1 FT93 This is a jobs name hjsimpson How satisfied were you with you account manager? 4 4 08232011 survey_list_20110823.csv this_is@anemailaddress.com MEM1 FT93 This is a jobs name hjsimpson How satisfied were you with the products and services Company XX offers? 3 This is another example of a random comment. This is is quite long so yeah, I dunno, what do you think about it? I was just starting to think to myself that this is just about long enough. Okay, well mayke just a little bit longer then.... Hmm, okay. 5 08232011 survey_list_20110823.csv this_is@anemailaddress.com MEM1 FT93 This is a jobs name hjsimpson How satisfied were you with the overall experience of working with Company XX? 4 The comments could potentially contain any characters they wanted so I am not going to be able to use the | character to delimit them. My Solution and Purpose for Posting: This is my conclusion to the problem at hand, I thought of a few others but this is the one I ended up writing. It works as expected, just looking to see what others might come up with. Enjoy data input; infile cards truncover; input data $512.; array _end[10] _end1-_end10; if _n_=1 then do _i=1 to dim(_end); retain _end:; if _i=1 then _end[_i]=find(data,'+',2); else _end[_i]=find(data,'+',_end[_i-1]+1); end; if substr(data,1,1)='+' then delete; if _n_=2 then delete; length list_name original_filename email_addr member jobno job_name ae question choice comment $256; array _var[10] list_name original_filename email_addr member jobno job_name ae question choice comment; do _j=1 to dim(_var); if _j=1 then _var[_j]=strip(substr(data,2,_end[_j]-2)); else _var[_j]=strip(substr(data,_end[_j-1]+2,_end[_j]-_end[_j-1]-2)); end; drop data _:; cards; +-----------+--------------------------+----------------------------+--------+-------+---------------------+-----------+--------------------------------------------------------------------------------+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | list_name | original_filename | email_addr | member | jobno | name | ae | content | choice | comment | +-----------+--------------------------+----------------------------+--------+-------+---------------------+-----------+--------------------------------------------------------------------------------+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 08232011 | survey_list_20110823.csv | this_is@anemailaddress.com | MEM1 | FT93 | This is a jobs name | hjsimpson | How satisfied were you with the accuracy of your order? | 4 | | | 08232011 | survey_list_20110823.csv | this_is@anemailaddress.com | MEM1 | FT93 | This is a jobs name | hjsimpson | How satisfied were you with the timeliness of your order? | 3 | This is some sort of random comment that the user has decided to leave in response to this question. | | 08232011 | survey_list_20110823.csv | this_is@anemailaddress.com | MEM1 | FT93 | This is a jobs name | hjsimpson | How satisfied were you with you account manager? | 4 | | | 08232011 | survey_list_20110823.csv | this_is@anemailaddress.com | MEM1 | FT93 | This is a jobs name | hjsimpson | How satisfied were you with the products and services Company XX offers? | 3 | This is another example of a random comment. This is is quite long so yeah, I dunno, what do you think about it? I was just starting to think to myself that this is just about long enough. Okay, well mayke just a little bit longer then.... Hmm, okay. | | 08232011 | survey_list_20110823.csv | this_is@anemailaddress.com | MEM1 | FT93 | This is a jobs name | hjsimpson | How satisfied were you with the overall experience of working with Company XX? | 4 | The comments could potentially contain any characters they wanted so I am not going to be able to use the | character to delimit them. | +-----------+--------------------------+----------------------------+--------+-------+---------------------+-----------+--------------------------------------------------------------------------------+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ; run;
... View more