BookmarkSubscribeRSS Feed
Aar684
Calcite | Level 5
Scott, I think your level of SAS knowledge is too far above mine to know what you mean without further explanation.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You've been given several code examples with which to start. Suggest reviewing the DOC on suggested call functions, come up with a program, come back to the forum for feedback, based on your results thus far.

Based on what you've seen so far, sure hope you have some sort of SAS program to work with, right?

Scott Barry
SBBWorks, Inc.
Aar684
Calcite | Level 5
I've been given several different ways to try this. I get close to having one set the way I want it then I get suggested another way to try it and I am back at square one. I was one step away from getting Peter's code working, the only thing I needed to was to keep leading zeros. You suggested something I'm not familiar with, so I asked for more detail. I have about 20 different sets of code I'm trying to make work for me.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If you notice, Peter.C has an early post which uses "PUT", "VVALUE" and "COMPRESS".....suggest working with that technique to begin with. And have a look at VFORMAT and PUTN functions in the SAS DOC or the SAS-hosted DOC on the support site.

I'm more inclined to lead instead of dragging, but there may be others on this forum who will do the coding for you.....by all means. In the meantime, let's see what you've got and go from there -- again, preferably in a SAS-generated log, not as your program.

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
Aar684
Calcite | Level 5
I really don't want the work done for me........if you don't want to help, don't. Implying that I do is quite contrary to the truth. I apologize if I seem that way,it just that this has been beyond frustrating. What you don't see are the 19 variants of code I've tried. I'm a self taught sas programmer(if you could even call me one) with a background in a bit of c++. I get nominated for these projects as I am the only here with any coding experience. I have the logical mind for it, just not the SAS knowledge, which I am working on.
Anyway, I'm working with what Peter and you have suggested.

1022 data helpme;
1023 file 'c:\aaron.txt' lrecl=10000 ;
1024 set work.trying ;
1025 put yvar1-yvar24 @;
1026 _file_= compress(_file_,'.');
1027 Put;
1028 run;

NOTE: The file 'c:\aaron.txt' is:
File Name=c:\aaron.txt,
RECFM=V,LRECL=10000

NOTE: 365 records were written to the file 'c:\aaron.txt'.
The minimum record length was 86.
The maximum record length was 95.
NOTE: There were 365 observations read from the data set WORK.TRYING.
NOTE: The data set WORK.HELPME has 365 observations and 28 variables.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.01 seconds

That works perfectly for removing the decimal points while keeping the leading zeros. However, it drops the trailing zeros, which is a problem for me. I think it might have to do with the actual data I import. I need to look into that.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
And help with guidance, I will try....here we go/continue....

You will need to consider the following additional points with your SAS program:

1) each SAS NUMERIC type variable has some type of output format, either explicit or SAS-default BEST. (observed from a SAS PROC CONTENTS listing, say using SASHELP.CLASS as a starter file to work with) -- and, so, a decision must be made (by the OP) whether or not to use the output format when generating the SAS CHARACTER variable interpretation (sounds like a YES, based on #2 and #3 below).
2) where decimal notation is found, it is to be removed, thus shortening some field lengths - observation being made here.
3) where leading or trailing zeros are present in the SAS database (not the external file by the way), apparently these are to be preserved, meaning there must be an output format used, because BEST. doesn't generate this behavior, such as Zw.d and others.
4) the incoming SAS variables of numeric type can be associated with an ARRAY for simplified DO/END loop processing -- need to learn about arrays.
5) the DATA step function VNAME can be used to extract the true SAS variable name for handling within the DO/END loop while using the ARRAY - need to look-up VNAME.
6) the DATA step function VFORMAT can be used to extract the true SAS output format name for handling within the DO/END loop while using the ARRAY - need to look-up VFORMAT.
7) the PUTN function can be used (along with info from #5 and #6 above) to generate a SAS CHARACTER variable (even as part of an array within the DO/END loop processing) - need to look-up PUTN.
8) the COMPRESS function can be used (along with the PUTN and related info) to manipulate the SAS CHARACTER variable in #7 above (as part of the array within the DO/END loop processing) - need to look-up COMPRESS.
9) after creating equivalent SAS CHARACTER variables for the SAS NUMERIC variables, another DO/END loop can be used with the PUT statement (to an external file) to output the data-record, one for each corresponding SAS observation.

Now, take each of the points for consideration and work on them one-at-a-time, as you build up your SAS program and learn about the DATA step processing, functions, and SAS variable value manipulation. As often as needed, come back to the forum with challenges/concerns, as your SAS program evolves. Frankly, you've chosen a medium- to advanced-level DATA step challenge, where there is input/output data manipulation and conversion involved --- a keen learning opportunity, I'd say.

You've got the SAS support http://support.sas.com/ website with SAS-hosted DOC and supplemental technical and conference reference material available for access, either using the website SEARCH facility or with crafting a Google advanced search argument (use the site:sas.com to limit the search).

Good luck!

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
change the picture - just slightly (of course only after you have read the on line doc about digits in the picture)
proc format ;
picture millis(round)
/* missing */ . = ' '
-9.999 - -0 = '12345'(mult=1000 prefix='-')
0 - 9.999 = '12345'(mult=1000)
other = [best5.]
;
run ;
%put testing millis %sysfunc( putn( 100/81, millis )) full precision %sysfunc( putn( 100/81, best16 )) ;
%put testing millis %sysfunc( putn(-100/81, millis )) full precision %sysfunc( putn(-100/81, best16 )) ;
%put testing millis %sysfunc( putn( 1, millis )) full precision %sysfunc( putn( 1, best16 )) ;
%put testing millis %sysfunc( putn(-1, millis )) full precision %sysfunc( putn(-1, best16 )) ;

the non-zero digits will alyways be non-blank
leading 0would be blank

try that
Peter_C
Rhodochrosite | Level 12
change the picture - just slightly (of course only after you have read the on line doc about digits in the picture)
proc format ;
picture millis(round)
/* missing */ . = ' '
-9.999 - -0 = '12345'(mult=1000 prefix='-')
0 - 9.999 = '12345'(mult=1000)
other = [best5.]
;
run ;
%put testing millis %sysfunc( putn( 100/81, millis )) full precision %sysfunc( putn( 100/81, best16 )) ;
%put testing millis %sysfunc( putn(-100/81, millis )) full precision %sysfunc( putn(-100/81, best16 )) ;
%put testing millis %sysfunc( putn( 1, millis )) full precision %sysfunc( putn( 1, best16 )) ;
%put testing millis %sysfunc( putn(-1, millis )) full precision %sysfunc( putn(-1, best16 )) ;

the non-zero digits will always be non-blank
leading 0would be blank

try that
Aar684
Calcite | Level 5
Thanks Scott and Peter. I just got in so I will begin working through your suggestions. I really, really do appreciate the time you guys take to help.
Ksharp
Super User
Hi.
Maybe you need the proper format.
Such as Zw.d.


[pre]
data peter;
input num;
char=compress(put(num,z5.3),'.');
datalines;
1.234
0.235
0.543
0.760
2.658
;run;
proc print;run;
[/pre]



Ksharp Message was edited by: Ksharp
Peter_C
Rhodochrosite | Level 12
If your export uses a data step, then it can be adapted to compress the entire file buffer in a single compress()
put varA varB varZ @;
_file_= compress(_file_,'.');
Put;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 25 replies
  • 29006 views
  • 0 likes
  • 5 in conversation