BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abarnett313
Calcite | Level 5

Greetings,

 

I am attempting to export a SAS database to a space-delimited text file so that it can be imported into Mplus. I'm using SAS v9.3. Here is the code I am using:

 

data _null_ ; /* No SAS data set is created */
set work3mergem;
FILE 'H:\Andrewtxtbpio0501';
PUT subject anyboy anyboy2 anyboy3 anyboy4 rsksum rsksum2 rsksum3 rsksum4 age a2 schcom11--schcom16 c1g
c2g c3g c4g c5g c6g c7g c8g c9g c10g c1o c2o c3o c4o c5o c6o c7o c8o c9o c10o b9--b14 a8a ethgrp;
run ;

 

When I run the code, there are several asterisks in the output file instead of the values as they show in SAS (some of which are recorded values, and some of which are missing values). There are 8 asterisks in all (from a data set with 500+ observations and 1,000+ variables), and they aren't all occurring for the same variable (i.e., for one case, there's an asterisk for variable b12, for another, b14). I am having difficulty figuring out why this is happening.

 

The data set was originally saved in SPSS, and so the first step of my program is to import it to SAS. I'm including that code, too, in case that may somehow be part of the problem:

 

libname inlib spss 'H:\Research\Huebner Paper HIV\FINAL DASH DATA_ONLY GOOD CASES.por';
proc convert spss=inlib out=huebhiv.dash050118;
run;

libname inlib spss 'H:\Research\Huebner Paper HIV\Oakland data_only good cases.por';
proc convert spss=inlib out=huebhiv.oakland050118;
run;

 

Any thoughts about why this might be happening and how to address it would be greatly appreciated. Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

A reasonable guess:  these variables have formats connected with them, that are not wide enough.  Just remove the formats:

 

data _null_;

set work3mergem;

format _numeric_;

FILE ........

View solution in original post

5 REPLIES 5
Astounding
PROC Star

A reasonable guess:  these variables have formats connected with them, that are not wide enough.  Just remove the formats:

 

data _null_;

set work3mergem;

format _numeric_;

FILE ........

abarnett313
Calcite | Level 5

That worked! Thank you very much. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Without some actual data its hard to say, but I would guess that the data is formatted, and the length is not long enough to handle the format - this happens with dates for instance.  

Also how are you opening the file?  You haven't given it a file extension (.txt for instance).  Now Excel is one app that likes to show data as * which it doesn't like.  So open the file in notepadd (/++) and see what the actual output looks like.

Otherwise post some data in the form of a datastep:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

So we have something to work with.

 

 

Tom
Super User Tom
Super User

That is usually an indication that the value cannot be display using the format that is attached.  For example trying to display a 5 digit number using the 4. format.  Some SAS functionality (like PROC IMPORT and SAS/Access) have a nasty habit of attaching formats to variables even when they do not need formats attached.

 

Check if any of the variables you are trying to write have formats attached to them. For example run a PROC CONTENTS on the dataset.

 

You could just try removing all of the formats using a format statement that lists variables without any format specification.  So you could just try adding this statement to your current data _null_ step.

format _all_ ;

But then if you have any variables that contain values like date, time or datetime that needs formats to display in a human readable way you will need make sure to use formats for those.  In that case add a second FORMAT statement to re-attach formats to just those variables that need them.

abarnett313
Calcite | Level 5

Thank you -- this was indeed the issue. I didn't have any variables that required special formatting, fortunately.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 2410 views
  • 0 likes
  • 4 in conversation