05-24-2016 11:32 AM
I have the following dataset. Each Varable length is exact length. For example patient_id has length 3 and variable_1 has legth 7.
When I export the dataset to .txt I get space between two variable (since I indicate dbms=tab in my output). Can anyone tell me how do I specify in PROC EXPORT so that I can avoid spcae in .txt file. Thanks,
patient_ID Var_1 Var_2 Var_3
101 LP28M72 LP23M66 LP22M64
101 LP29M64 NOTUSED NOTUSED
102 SR66F76 SR62F76 SR61F76
102 SR69F76 SR77F76 NOTUSED
103 JH23F56 JH43F56 NOTUSED
here is my code:
05-24-2016 11:47 AM
If you don't want space between variables then why specify TAB in the first place?
If I understand your requirement you may need to go old school as Proc Export want some sort of file type and a delimiter, so you would get a character between values.
Something like this may give you what you want:
data _null_; set have; file 'C:\Users\want.txt' ; length line $ 25; /* large enough to hold all the variables*/ line = catt(patientid,var_1,var_2,var_3); put line; run;
Though Fixed column isn't popular anymore.
05-24-2016 11:57 AM
05-24-2016 12:14 PM
There's nothing wrong with making line 750 characters long. The only trick is making the CATT statement.
If you aren't making a whole bunch of these files then use proc export with a space or other character and then use a text editor to remove all of them. Not slick and the extra step isn't really a good idea.
The real old school approach was to use Put statements with fixed column start points, which may be a good idea if you ever run into a variable with varying length:
Put @1 Id @36 Var_1 @71 var_2 @106 var_3 <etc> ;
Would place them at fixed positions. There is syntax that lets specify that with parantheses and variable lists but research the PUT statement for more details on Column output.
05-31-2016 01:11 PM
05-24-2016 04:03 PM - edited 05-24-2016 04:04 PM
Look at the manual on the PUT statement.
If you want to skip 12 spaces then just at +12 to the PUT statement.
put id $3. +12 var1 $7. ....
If you want to tell SAS to use 15 instead of 3 columns for the ID variable then just use a longer format.
put id $15. ....
Or you can also tell it to go the particular column where you want to put the variable.
put id $3. @16 var1 $7. ...
You can combine them in many ways. Just don't try to put more characters than can fit or else the values will overwrite each other.
put @15 var1 @1 id @22 var2 ...
05-24-2016 09:17 PM
Most likely that is the default for the LRECL option on your verison of SAS.
Add the LRECL= option to the FILE statement. You can set it really large as SAS will only write the number of characters you actually tell it to in the PUT statement. 32767 is a nice number to use since it is 2**15-1.
file 'myfile.txt' lrecl=32767 ;
Need further help from the community? Please ask a new question.